source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/CategoryTheory/Filtered/Small.lean
import Mathlib.CategoryTheory.EssentiallySmall import Mathlib.CategoryTheory.Filtered.Basic import Mathlib.Tactic.DepRewrite /-! # A functor from a small category to a filtered category factors through a small filtered category A consequence of this is that if `C` is filtered and finally small, then `C` is also "finally filtered-small", i.e., there is a final functor from a small filtered category to `C`. This is occasionally useful, for example in the proof of the recognition theorem for ind-objects (Proposition 6.1.5 in [Kashiwara2006]). -/ universe w v v₁ u u₁ namespace CategoryTheory variable {C : Type u} [Category.{v} C] namespace IsFiltered section filteredClosure variable [IsFilteredOrEmpty C] {α : Type w} (f : α → C) /-- The "filtered closure" of an `α`-indexed family of objects in `C` is the set of objects in `C` obtained by starting with the family and successively adding maxima and coequalizers. -/ inductive filteredClosure : ObjectProperty C | base : (x : α) → filteredClosure (f x) | max : {j j' : C} → filteredClosure j → filteredClosure j' → filteredClosure (max j j') | coeq : {j j' : C} → filteredClosure j → filteredClosure j' → (f f' : j ⟶ j') → filteredClosure (coeq f f') /-- The full subcategory induced by the filtered closure of a family of objects is filtered. -/ instance : IsFilteredOrEmpty (filteredClosure f).FullSubcategory where cocone_objs j j' := ⟨⟨max j.1 j'.1, filteredClosure.max j.2 j'.2⟩, leftToMax _ _, rightToMax _ _, trivial⟩ cocone_maps {j j'} f f' := ⟨⟨coeq f f', filteredClosure.coeq j.2 j'.2 f f'⟩, coeqHom (C := C) f f', coeq_condition _ _⟩ namespace FilteredClosureSmall /-! Our goal for this section is to show that the size of the filtered closure of an `α`-indexed family of objects in `C` only depends on the size of `α` and the morphism types of `C`, not on the size of the objects of `C`. More precisely, if `α` lives in `Type w`, the objects of `C` live in `Type u` and the morphisms of `C` live in `Type v`, then we want `Small.{max v w} (FullSubcategory (filteredClosure f))`. The strategy is to define a type `AbstractFilteredClosure` which should be an inductive type similar to `filteredClosure`, which lives in the correct universe and surjects onto the full subcategory. The difficulty with this is that we need to define it at the same time as the map `AbstractFilteredClosure → C`, as the coequalizer constructor depends on the actual morphisms in `C`. This would require some kind of inductive-recursive definition, which Lean does not allow. Our solution is to define a function `ℕ → Σ t : Type (max v w), t → C` by (strong) induction and then take the union over all natural numbers, mimicking what one would do in a set-theoretic setting. -/ /-- One step of the inductive procedure consists of adjoining all maxima and coequalizers of all objects and morphisms obtained so far. This is quite redundant, picking up many objects which we already hit in earlier iterations, but this is easier to work with later. -/ private inductive InductiveStep (n : ℕ) (X : ∀ (k : ℕ), k < n → Σ t : Type (max v w), t → C) : Type (max v w) | max : {k k' : ℕ} → (hk : k < n) → (hk' : k' < n) → (X _ hk).1 → (X _ hk').1 → InductiveStep n X | coeq : {k k' : ℕ} → (hk : k < n) → (hk' : k' < n) → (j : (X _ hk).1) → (j' : (X _ hk').1) → ((X _ hk).2 j ⟶ (X _ hk').2 j') → ((X _ hk).2 j ⟶ (X _ hk').2 j') → InductiveStep n X /-- The realization function sends the abstract maxima and weak coequalizers to the corresponding objects in `C`. -/ private noncomputable def inductiveStepRealization (n : ℕ) (X : ∀ (k : ℕ), k < n → Σ t : Type (max v w), t → C) : InductiveStep.{w} n X → C | (InductiveStep.max hk hk' x y) => max ((X _ hk).2 x) ((X _ hk').2 y) | (InductiveStep.coeq _ _ _ _ f g) => coeq f g /-- All steps of building the abstract filtered closure together with the realization function, as a function of `ℕ`. -/ private noncomputable def bundledAbstractFilteredClosure : ℕ → Σ t : Type (max v w), t → C | 0 => ⟨ULift.{v} α, f ∘ ULift.down⟩ | (n + 1) => ⟨_, inductiveStepRealization (n + 1) (fun m _ => bundledAbstractFilteredClosure m)⟩ /-- The small type modelling the filtered closure. -/ private noncomputable def AbstractFilteredClosure : Type (max v w) := Σ n, (bundledAbstractFilteredClosure f n).1 /-- The surjection from the abstract filtered closure to the actual filtered closure in `C`. -/ private noncomputable def abstractFilteredClosureRealization : AbstractFilteredClosure f → C := fun x => (bundledAbstractFilteredClosure f x.1).2 x.2 end FilteredClosureSmall theorem small_fullSubcategory_filteredClosure : Small.{max v w} (filteredClosure f).FullSubcategory := by refine small_of_injective_of_exists (FilteredClosureSmall.abstractFilteredClosureRealization f) (fun _ _ => ObjectProperty.FullSubcategory.ext) ?_ rintro ⟨j, h⟩ induction h with | base x => refine ⟨⟨0, ?_⟩, ?_⟩ · simp only [FilteredClosureSmall.bundledAbstractFilteredClosure] exact ULift.up x · simp only [FilteredClosureSmall.abstractFilteredClosureRealization] rw! [FilteredClosureSmall.bundledAbstractFilteredClosure] rfl | max hj₁ hj₂ ih ih' => rcases ih with ⟨⟨n, x⟩, rfl⟩ rcases ih' with ⟨⟨m, y⟩, rfl⟩ refine ⟨⟨(Max.max n m).succ, ?_⟩, ?_⟩ · simp only [FilteredClosureSmall.bundledAbstractFilteredClosure] refine FilteredClosureSmall.InductiveStep.max ?_ ?_ x y all_goals apply Nat.lt_succ_of_le exacts [Nat.le_max_left _ _, Nat.le_max_right _ _] · simp only [FilteredClosureSmall.abstractFilteredClosureRealization] rw! [FilteredClosureSmall.bundledAbstractFilteredClosure] rfl | coeq hj₁ hj₂ g g' ih ih' => rcases ih with ⟨⟨n, x⟩, rfl⟩ rcases ih' with ⟨⟨m, y⟩, rfl⟩ refine ⟨⟨(Max.max n m).succ, ?_⟩, ?_⟩ · simp only [FilteredClosureSmall.bundledAbstractFilteredClosure] refine FilteredClosureSmall.InductiveStep.coeq ?_ ?_ x y g g' all_goals apply Nat.lt_succ_of_le exacts [Nat.le_max_left _ _, Nat.le_max_right _ _] · simp only [FilteredClosureSmall.abstractFilteredClosureRealization] rw! [FilteredClosureSmall.bundledAbstractFilteredClosure] rfl instance : EssentiallySmall.{max v w} (filteredClosure f).FullSubcategory := have : LocallySmall.{max v w} (filteredClosure f).FullSubcategory := locallySmall_max.{w, v, u} have := small_fullSubcategory_filteredClosure f essentiallySmall_of_small_of_locallySmall _ end filteredClosure section variable [IsFilteredOrEmpty C] {D : Type u₁} [Category.{v₁} D] (F : D ⥤ C) /-- Every functor from a small category to a filtered category factors fully faithfully through a small filtered category. This is that category. -/ def SmallFilteredIntermediate : Type (max u₁ v) := SmallModel.{max u₁ v} (filteredClosure F.obj).FullSubcategory noncomputable instance : SmallCategory (SmallFilteredIntermediate F) := inferInstanceAs (SmallCategory (SmallModel (filteredClosure F.obj).FullSubcategory)) namespace SmallFilteredIntermediate /-- The first part of a factoring of a functor from a small category to a filtered category through a small filtered category. -/ noncomputable def factoring : D ⥤ SmallFilteredIntermediate F := ObjectProperty.lift _ F filteredClosure.base ⋙ (equivSmallModel _).functor /-- The second, fully faithful part of a factoring of a functor from a small category to a filtered category through a small filtered category. -/ noncomputable def inclusion : SmallFilteredIntermediate F ⥤ C := (equivSmallModel _).inverse ⋙ ObjectProperty.ι _ instance : (inclusion F).Faithful := inferInstanceAs ((equivSmallModel _).inverse ⋙ ObjectProperty.ι _).Faithful noncomputable instance : (inclusion F).Full := inferInstanceAs ((equivSmallModel _).inverse ⋙ ObjectProperty.ι _).Full /-- The factorization through a small filtered category is in fact a factorization, up to natural isomorphism. -/ noncomputable def factoringCompInclusion : factoring F ⋙ inclusion F ≅ F := Functor.isoWhiskerLeft _ (Functor.isoWhiskerRight (Equivalence.unitIso _).symm _) instance : IsFilteredOrEmpty (SmallFilteredIntermediate F) := IsFilteredOrEmpty.of_equivalence (equivSmallModel _) instance [Nonempty D] : IsFiltered (SmallFilteredIntermediate F) := { (inferInstance : IsFilteredOrEmpty _) with nonempty := Nonempty.map (factoring F).obj inferInstance } end SmallFilteredIntermediate end end IsFiltered namespace IsCofiltered section cofilteredClosure variable [IsCofilteredOrEmpty C] {α : Type w} (f : α → C) /-- The "cofiltered closure" of an `α`-indexed family of objects in `C` is the set of objects in `C` obtained by starting with the family and successively adding minima and equalizers. -/ inductive cofilteredClosure : ObjectProperty C | base : (x : α) → cofilteredClosure (f x) | min : {j j' : C} → cofilteredClosure j → cofilteredClosure j' → cofilteredClosure (min j j') | eq : {j j' : C} → cofilteredClosure j → cofilteredClosure j' → (f f' : j ⟶ j') → cofilteredClosure (eq f f') /-- The full subcategory induced by the cofiltered closure of a family is cofiltered. -/ instance : IsCofilteredOrEmpty (cofilteredClosure f).FullSubcategory where cone_objs j j' := ⟨⟨min j.1 j'.1, cofilteredClosure.min j.2 j'.2⟩, minToLeft _ _, minToRight _ _, trivial⟩ cone_maps {j j'} f f' := ⟨⟨eq f f', cofilteredClosure.eq j.2 j'.2 f f'⟩, eqHom (C := C) f f', eq_condition _ _⟩ namespace CofilteredClosureSmall /-- Implementation detail for the instance `EssentiallySmall.{max v w} (FullSubcategory (cofilteredClosure f))`. -/ private inductive InductiveStep (n : ℕ) (X : ∀ (k : ℕ), k < n → Σ t : Type (max v w), t → C) : Type (max v w) | min : {k k' : ℕ} → (hk : k < n) → (hk' : k' < n) → (X _ hk).1 → (X _ hk').1 → InductiveStep n X | eq : {k k' : ℕ} → (hk : k < n) → (hk' : k' < n) → (j : (X _ hk).1) → (j' : (X _ hk').1) → ((X _ hk).2 j ⟶ (X _ hk').2 j') → ((X _ hk).2 j ⟶ (X _ hk').2 j') → InductiveStep n X /-- Implementation detail for the instance `EssentiallySmall.{max v w} (FullSubcategory (cofilteredClosure f))`. -/ private noncomputable def inductiveStepRealization (n : ℕ) (X : ∀ (k : ℕ), k < n → Σ t : Type (max v w), t → C) : InductiveStep.{w} n X → C | (InductiveStep.min hk hk' x y) => min ((X _ hk).2 x) ((X _ hk').2 y) | (InductiveStep.eq _ _ _ _ f g) => eq f g /-- Implementation detail for the instance `EssentiallySmall.{max v w} (FullSubcategory (cofilteredClosure f))`. -/ private noncomputable def bundledAbstractCofilteredClosure : ℕ → Σ t : Type (max v w), t → C | 0 => ⟨ULift.{v} α, f ∘ ULift.down⟩ | (n + 1) => ⟨_, inductiveStepRealization (n + 1) (fun m _ => bundledAbstractCofilteredClosure m)⟩ /-- Implementation detail for the instance `EssentiallySmall.{max v w} (FullSubcategory (cofilteredClosure f))`. -/ private noncomputable def AbstractCofilteredClosure : Type (max v w) := Σ n, (bundledAbstractCofilteredClosure f n).1 /-- Implementation detail for the instance `EssentiallySmall.{max v w} (FullSubcategory (cofilteredClosure f))`. -/ private noncomputable def abstractCofilteredClosureRealization : AbstractCofilteredClosure f → C := fun x => (bundledAbstractCofilteredClosure f x.1).2 x.2 end CofilteredClosureSmall theorem small_fullSubcategory_cofilteredClosure : Small.{max v w} (cofilteredClosure f).FullSubcategory := by refine small_of_injective_of_exists (CofilteredClosureSmall.abstractCofilteredClosureRealization f) (fun _ _ => ObjectProperty.FullSubcategory.ext) ?_ rintro ⟨j, h⟩ induction h with | base x => refine ⟨⟨0, ?_⟩,?_⟩ · simp only [CofilteredClosureSmall.bundledAbstractCofilteredClosure] exact ULift.up x · simp only [CofilteredClosureSmall.abstractCofilteredClosureRealization] rw! [CofilteredClosureSmall.bundledAbstractCofilteredClosure] rfl | min hj₁ hj₂ ih ih' => rcases ih with ⟨⟨n, x⟩, rfl⟩ rcases ih' with ⟨⟨m, y⟩, rfl⟩ refine ⟨⟨(Max.max n m).succ, ?_⟩, ?_⟩ · simp only [CofilteredClosureSmall.bundledAbstractCofilteredClosure] refine CofilteredClosureSmall.InductiveStep.min ?_ ?_ x y all_goals apply Nat.lt_succ_of_le exacts [Nat.le_max_left _ _, Nat.le_max_right _ _] · simp only [CofilteredClosureSmall.abstractCofilteredClosureRealization] rw! [CofilteredClosureSmall.bundledAbstractCofilteredClosure] rfl | eq hj₁ hj₂ g g' ih ih' => rcases ih with ⟨⟨n, x⟩, rfl⟩ rcases ih' with ⟨⟨m, y⟩, rfl⟩ refine ⟨⟨(Max.max n m).succ, ?_⟩, ?_⟩ · simp only [CofilteredClosureSmall.bundledAbstractCofilteredClosure] refine CofilteredClosureSmall.InductiveStep.eq ?_ ?_ x y g g' all_goals apply Nat.lt_succ_of_le exacts [Nat.le_max_left _ _, Nat.le_max_right _ _] · simp only [CofilteredClosureSmall.abstractCofilteredClosureRealization] rw! [CofilteredClosureSmall.bundledAbstractCofilteredClosure] rfl instance : EssentiallySmall.{max v w} (cofilteredClosure f).FullSubcategory := have : LocallySmall.{max v w} (cofilteredClosure f).FullSubcategory := locallySmall_max.{w, v, u} have := small_fullSubcategory_cofilteredClosure f essentiallySmall_of_small_of_locallySmall _ end cofilteredClosure section variable [IsCofilteredOrEmpty C] {D : Type u₁} [Category.{v₁} D] (F : D ⥤ C) /-- Every functor from a small category to a cofiltered category factors fully faithfully through a small cofiltered category. This is that category. -/ def SmallCofilteredIntermediate : Type (max u₁ v) := SmallModel.{max u₁ v} (cofilteredClosure F.obj).FullSubcategory noncomputable instance : SmallCategory (SmallCofilteredIntermediate F) := inferInstanceAs (SmallCategory (SmallModel (cofilteredClosure F.obj).FullSubcategory)) namespace SmallCofilteredIntermediate /-- The first part of a factoring of a functor from a small category to a cofiltered category through a small filtered category. -/ noncomputable def factoring : D ⥤ SmallCofilteredIntermediate F := ObjectProperty.lift _ F cofilteredClosure.base ⋙ (equivSmallModel _).functor /-- The second, fully faithful part of a factoring of a functor from a small category to a filtered category through a small filtered category. -/ noncomputable def inclusion : SmallCofilteredIntermediate F ⥤ C := (equivSmallModel _).inverse ⋙ ObjectProperty.ι _ instance : (inclusion F).Faithful := inferInstanceAs ((equivSmallModel _).inverse ⋙ ObjectProperty.ι _).Faithful noncomputable instance : (inclusion F).Full := inferInstanceAs ((equivSmallModel _).inverse ⋙ ObjectProperty.ι _).Full /-- The factorization through a small filtered category is in fact a factorization, up to natural isomorphism. -/ noncomputable def factoringCompInclusion : factoring F ⋙ inclusion F ≅ F := Functor.isoWhiskerLeft _ (Functor.isoWhiskerRight (Equivalence.unitIso _).symm _) instance : IsCofilteredOrEmpty (SmallCofilteredIntermediate F) := IsCofilteredOrEmpty.of_equivalence (equivSmallModel _) instance [Nonempty D] : IsCofiltered (SmallCofilteredIntermediate F) := { (inferInstance : IsCofilteredOrEmpty _) with nonempty := Nonempty.map (factoring F).obj inferInstance } end SmallCofilteredIntermediate end end IsCofiltered end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Filtered/Grothendieck.lean
import Mathlib.CategoryTheory.Filtered.Basic import Mathlib.CategoryTheory.Grothendieck /-! # Filteredness of Grothendieck construction We show that if `F : C ⥤ Cat` is such that `C` is filtered and `F.obj c` is filtered for all `c : C`, then `Grothendieck F` is filtered. -/ universe v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] (F : C ⥤ Cat) open IsFiltered instance [IsFilteredOrEmpty C] [∀ c, IsFilteredOrEmpty (F.obj c)] : IsFilteredOrEmpty (Grothendieck F) := by refine ⟨?_, ?_⟩ · rintro ⟨c, f⟩ ⟨d, g⟩ exact ⟨⟨max c d, max ((F.map (leftToMax c d)).obj f) ((F.map (rightToMax c d)).obj g)⟩, ⟨leftToMax c d, leftToMax _ _⟩, ⟨rightToMax c d, rightToMax _ _⟩, trivial⟩ · rintro ⟨c, f⟩ ⟨d, g⟩ ⟨u, x⟩ ⟨v, y⟩ refine ⟨⟨coeq u v, coeq (eqToHom ?_ ≫ (F.map (coeqHom u v)).map x) ((F.map (coeqHom u v)).map y)⟩, ⟨coeqHom u v, coeqHom _ _⟩, ?_⟩ · conv_rhs => rw [← Cat.comp_obj, ← F.map_comp, coeq_condition, F.map_comp, Cat.comp_obj] · apply Grothendieck.ext _ _ (coeq_condition u v) refine Eq.trans ?_ (eqToHom _ ≫= coeq_condition _ _) simp instance [IsFiltered C] [∀ c, IsFiltered (F.obj c)] : IsFiltered (Grothendieck F) := by have : Nonempty (Grothendieck F) := by obtain ⟨c⟩ : Nonempty C := IsFiltered.nonempty obtain ⟨f⟩ : Nonempty (F.obj c) := IsFiltered.nonempty exact ⟨⟨c, f⟩⟩ apply IsFiltered.mk end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Filtered/Connected.lean
import Mathlib.CategoryTheory.Filtered.Basic import Mathlib.CategoryTheory.IsConnected /-! # Filtered categories are connected -/ universe v u namespace CategoryTheory variable (C : Type u) [Category.{v} C] theorem IsFilteredOrEmpty.isPreconnected [IsFilteredOrEmpty C] : IsPreconnected C := zigzag_isPreconnected fun j j' => .trans (.single <| .inl <| .intro <| IsFiltered.leftToMax j j') (.single <| .inr <| .intro <| IsFiltered.rightToMax j j') theorem IsCofilteredOrEmpty.isPreconnected [IsCofilteredOrEmpty C] : IsPreconnected C := zigzag_isPreconnected fun j j' => .trans (.single <| .inr <| .intro <| IsCofiltered.minToLeft j j') (.single <| .inl <| .intro <| IsCofiltered.minToRight j j') attribute [local instance] IsFiltered.nonempty in theorem IsFiltered.isConnected [IsFiltered C] : IsConnected C := { IsFilteredOrEmpty.isPreconnected C with } attribute [local instance] IsCofiltered.nonempty in theorem IsCofiltered.isConnected [IsCofiltered C] : IsConnected C := { IsCofilteredOrEmpty.isPreconnected C with } end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Filtered/CostructuredArrow.lean
import Mathlib.CategoryTheory.Filtered.OfColimitCommutesFiniteLimit import Mathlib.CategoryTheory.Functor.KanExtension.Adjunction import Mathlib.CategoryTheory.Limits.FilteredColimitCommutesFiniteLimit import Mathlib.CategoryTheory.Limits.Preserves.Grothendieck import Mathlib.CategoryTheory.Limits.Final /-! # Inferring Filteredness from Filteredness of Costructured Arrow Categories ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Proposition 3.1.8 -/ universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory open Limits Functor section Small variable {A : Type u₁} [SmallCategory A] {B : Type u₁} [SmallCategory B] variable {T : Type u₁} [SmallCategory T] private lemma isFiltered_of_isFiltered_costructuredArrow_small (L : A ⥤ T) (R : B ⥤ T) [IsFiltered B] [Final R] [∀ b, IsFiltered (CostructuredArrow L (R.obj b))] : IsFiltered A := by refine isFiltered_of_nonempty_limit_colimit_to_colimit_limit fun J {_ _} F => ⟨?_⟩ let R' := Grothendieck.pre (CostructuredArrow.functor L) R haveI : ∀ b, PreservesLimitsOfShape J (colim (J := (R ⋙ CostructuredArrow.functor L).obj b) (C := Type u₁)) := fun b => by simp only [comp_obj, CostructuredArrow.functor_obj, Cat.of_α] exact filtered_colim_preservesFiniteLimits refine lim.map ((colimitIsoColimitGrothendieck L F.flip).hom ≫ (inv (colimit.pre (CostructuredArrow.grothendieckProj L ⋙ F.flip) R'))) ≫ (colimitLimitIso (R' ⋙ CostructuredArrow.grothendieckProj L ⋙ F.flip).flip).inv ≫ colim.map ?_ ≫ colimit.pre _ R' ≫ (colimitIsoColimitGrothendieck L (limit F)).inv exact (limitCompWhiskeringLeftIsoCompLimit F (R' ⋙ CostructuredArrow.grothendieckProj L)).hom end Small variable {A : Type u₁} [Category.{v₁} A] {B : Type u₂} [Category.{v₂} B] variable {T : Type u₃} [Category.{v₃} T] /-- Given functors `L : A ⥤ T` and `R : B ⥤ T` with a common codomain we can conclude that `A` is filtered given that `R` is final, `B` is filtered and each costructured arrow category `CostructuredArrow L (R.obj b)` is filtered. -/ theorem isFiltered_of_isFiltered_costructuredArrow (L : A ⥤ T) (R : B ⥤ T) [IsFiltered B] [Final R] [∀ b, IsFiltered (CostructuredArrow L (R.obj b))] : IsFiltered A := by let sA : A ≌ AsSmall.{max u₁ u₂ u₃ v₁ v₂ v₃} A := AsSmall.equiv let sB : B ≌ AsSmall.{max u₁ u₂ u₃ v₁ v₂ v₃} B := AsSmall.equiv let sT : T ≌ AsSmall.{max u₁ u₂ u₃ v₁ v₂ v₃} T := AsSmall.equiv let sC : ∀ b, CostructuredArrow (sA.inverse ⋙ L ⋙ sT.functor) ((sB.inverse ⋙ R ⋙ sT.functor).obj ⟨b⟩) ≌ CostructuredArrow L (R.obj b) := fun b => (CostructuredArrow.pre sA.inverse (L ⋙ sT.functor) _).asEquivalence.trans (CostructuredArrow.post L sT.functor _).asEquivalence.symm haveI : ∀ b, IsFiltered (CostructuredArrow _ ((sB.inverse ⋙ R ⋙ sT.functor).obj b)) := fun b => IsFiltered.of_equivalence (sC b.1).symm haveI := isFiltered_of_isFiltered_costructuredArrow_small (sA.inverse ⋙ L ⋙ sT.functor) (sB.inverse ⋙ R ⋙ sT.functor) exact IsFiltered.of_equivalence sA.symm end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sigma/Basic.lean
import Mathlib.CategoryTheory.Whiskering import Mathlib.CategoryTheory.Functor.FullyFaithful import Mathlib.CategoryTheory.NatIso /-! # Disjoint union of categories We define the category structure on a sigma-type (disjoint union) of categories. -/ namespace CategoryTheory namespace Sigma universe w₁ w₂ w₃ v₁ v₂ u₁ u₂ variable {I : Type w₁} {C : I → Type u₁} [∀ i, Category.{v₁} (C i)] /-- The type of morphisms of a disjoint union of categories: for `X : C i` and `Y : C j`, a morphism `(i, X) ⟶ (j, Y)` if `i = j` is just a morphism `X ⟶ Y`, and if `i ≠ j` there are no such morphisms. -/ inductive SigmaHom : (Σ i, C i) → (Σ i, C i) → Type max w₁ v₁ u₁ | mk : ∀ {i : I} {X Y : C i}, (X ⟶ Y) → SigmaHom ⟨i, X⟩ ⟨i, Y⟩ namespace SigmaHom /-- The identity morphism on an object. -/ def id : ∀ X : Σ i, C i, SigmaHom X X | ⟨_, _⟩ => mk (𝟙 _) instance (X : Σ i, C i) : Inhabited (SigmaHom X X) := ⟨id X⟩ /-- Composition of sigma homomorphisms. -/ def comp : ∀ {X Y Z : Σ i, C i}, SigmaHom X Y → SigmaHom Y Z → SigmaHom X Z | _, _, _, mk f, mk g => mk (f ≫ g) instance : CategoryStruct (Σ i, C i) where Hom := SigmaHom id := id comp f g := comp f g @[simp] lemma comp_def (i : I) (X Y Z : C i) (f : X ⟶ Y) (g : Y ⟶ Z) : comp (mk f) (mk g) = mk (f ≫ g) := rfl lemma assoc : ∀ {X Y Z W : Σ i, C i} (f : X ⟶ Y) (g : Y ⟶ Z) (h : Z ⟶ W), (f ≫ g) ≫ h = f ≫ g ≫ h | _, _, _, _, mk _, mk _, mk _ => congr_arg mk (Category.assoc _ _ _) lemma id_comp : ∀ {X Y : Σ i, C i} (f : X ⟶ Y), 𝟙 X ≫ f = f | _, _, mk _ => congr_arg mk (Category.id_comp _) lemma comp_id : ∀ {X Y : Σ i, C i} (f : X ⟶ Y), f ≫ 𝟙 Y = f | _, _, mk _ => congr_arg mk (Category.comp_id _) end SigmaHom instance sigma : Category (Σ i, C i) where id_comp := SigmaHom.id_comp comp_id := SigmaHom.comp_id assoc := SigmaHom.assoc /-- The inclusion functor into the disjoint union of categories. -/ @[simps map] def incl (i : I) : C i ⥤ Σ i, C i where obj X := ⟨i, X⟩ map := SigmaHom.mk @[simp] lemma incl_obj {i : I} (X : C i) : (incl i).obj X = ⟨i, X⟩ := rfl instance (i : I) : Functor.Full (incl i : C i ⥤ Σ i, C i) where map_surjective := fun ⟨f⟩ => ⟨f, rfl⟩ instance (i : I) : Functor.Faithful (incl i : C i ⥤ Σ i, C i) where map_injective {_ _ _ _} h := by injection h section variable {D : Type u₂} [Category.{v₂} D] (F : ∀ i, C i ⥤ D) /-- To build a natural transformation over the sigma category, it suffices to specify it restricted to each subcategory. -/ def natTrans {F G : (Σ i, C i) ⥤ D} (h : ∀ i : I, incl i ⋙ F ⟶ incl i ⋙ G) : F ⟶ G where app := fun ⟨j, X⟩ => (h j).app X naturality := by rintro ⟨j, X⟩ ⟨_, _⟩ ⟨f⟩ apply (h j).naturality @[simp] lemma natTrans_app {F G : (Σ i, C i) ⥤ D} (h : ∀ i : I, incl i ⋙ F ⟶ incl i ⋙ G) (i : I) (X : C i) : (natTrans h).app ⟨i, X⟩ = (h i).app X := rfl /-- (Implementation). An auxiliary definition to build the functor `desc`. -/ def descMap : ∀ X Y : Σ i, C i, (X ⟶ Y) → ((F X.1).obj X.2 ⟶ (F Y.1).obj Y.2) | _, _, SigmaHom.mk g => (F _).map g /-- Given a collection of functors `F i : C i ⥤ D`, we can produce a functor `(Σ i, C i) ⥤ D`. The produced functor `desc F` satisfies: `incl i ⋙ desc F ≅ F i`, i.e. restricted to just the subcategory `C i`, `desc F` agrees with `F i`, and it is unique (up to natural isomorphism) with this property. This witnesses that the sigma-type is the coproduct in Cat. -/ @[simps obj] def desc : (Σ i, C i) ⥤ D where obj X := (F X.1).obj X.2 map g := descMap F _ _ g map_id := by rintro ⟨i, X⟩ apply (F i).map_id map_comp := by rintro ⟨i, X⟩ ⟨_, Y⟩ ⟨_, Z⟩ ⟨f⟩ ⟨g⟩ apply (F i).map_comp @[simp] lemma desc_map_mk {i : I} (X Y : C i) (f : X ⟶ Y) : (desc F).map (SigmaHom.mk f) = (F i).map f := rfl -- We hand-generate the simp lemmas about this since they come out cleaner. /-- This shows that when `desc F` is restricted to just the subcategory `C i`, `desc F` agrees with `F i`. -/ def inclDesc (i : I) : incl i ⋙ desc F ≅ F i := NatIso.ofComponents fun _ => Iso.refl _ @[simp] lemma inclDesc_hom_app (i : I) (X : C i) : (inclDesc F i).hom.app X = 𝟙 ((F i).obj X) := rfl @[simp] lemma inclDesc_inv_app (i : I) (X : C i) : (inclDesc F i).inv.app X = 𝟙 ((F i).obj X) := rfl /-- If `q` when restricted to each subcategory `C i` agrees with `F i`, then `q` is isomorphic to `desc F`. -/ def descUniq (q : (Σ i, C i) ⥤ D) (h : ∀ i, incl i ⋙ q ≅ F i) : q ≅ desc F := NatIso.ofComponents (fun ⟨i, X⟩ => (h i).app X) <| by rintro ⟨i, X⟩ ⟨_, _⟩ ⟨f⟩ apply (h i).hom.naturality f @[simp] lemma descUniq_hom_app (q : (Σ i, C i) ⥤ D) (h : ∀ i, incl i ⋙ q ≅ F i) (i : I) (X : C i) : (descUniq F q h).hom.app ⟨i, X⟩ = (h i).hom.app X := rfl @[simp] lemma descUniq_inv_app (q : (Σ i, C i) ⥤ D) (h : ∀ i, incl i ⋙ q ≅ F i) (i : I) (X : C i) : (descUniq F q h).inv.app ⟨i, X⟩ = (h i).inv.app X := rfl /-- If `q₁` and `q₂` when restricted to each subcategory `C i` agree, then `q₁` and `q₂` are isomorphic. -/ @[simps] def natIso {q₁ q₂ : (Σ i, C i) ⥤ D} (h : ∀ i, incl i ⋙ q₁ ≅ incl i ⋙ q₂) : q₁ ≅ q₂ where hom := natTrans fun i => (h i).hom inv := natTrans fun i => (h i).inv end section variable (C) {J : Type w₂} (g : J → I) /-- A function `J → I` induces a functor `Σ j, C (g j) ⥤ Σ i, C i`. -/ def map : (Σ j : J, C (g j)) ⥤ Σ i : I, C i := desc fun j => incl (g j) @[simp] lemma map_obj (j : J) (X : C (g j)) : (Sigma.map C g).obj ⟨j, X⟩ = ⟨g j, X⟩ := rfl @[simp] lemma map_map {j : J} {X Y : C (g j)} (f : X ⟶ Y) : (Sigma.map C g).map (SigmaHom.mk f) = SigmaHom.mk f := rfl /-- The functor `Sigma.map C g` restricted to the subcategory `C j` acts as the inclusion of `g j`. -/ @[simps!] def inclCompMap (j : J) : incl j ⋙ map C g ≅ incl (g j) := Iso.refl _ variable (I) /-- The functor `Sigma.map` applied to the identity function is just the identity functor. -/ @[simps!] def mapId : map C (id : I → I) ≅ 𝟭 (Σ i, C i) := natIso fun i => NatIso.ofComponents fun _ => Iso.refl _ variable {I} {K : Type w₃} /-- The functor `Sigma.map` applied to a composition is a composition of functors. -/ @[simps!] def mapComp (f : K → J) (g : J → I) : map (fun x ↦ C (g x)) f ⋙ (map C g :) ≅ map C (g ∘ f) := (descUniq _ _) fun k => (Functor.isoWhiskerRight (inclCompMap _ f k) (map C g :) :) ≪≫ inclCompMap _ g (f k) end namespace Functor -- variable {C} variable {D : I → Type u₁} [∀ i, Category.{v₁} (D i)] /-- Assemble an `I`-indexed family of functors into a functor between the sigma types. -/ def sigma (F : ∀ i, C i ⥤ D i) : (Σ i, C i) ⥤ Σ i, D i := desc fun i => F i ⋙ incl i end Functor namespace natTrans variable {D : I → Type u₁} [∀ i, Category.{v₁} (D i)] variable {F G : ∀ i, C i ⥤ D i} /-- Assemble an `I`-indexed family of natural transformations into a single natural transformation. -/ def sigma (α : ∀ i, F i ⟶ G i) : Functor.sigma F ⟶ Functor.sigma G where app f := SigmaHom.mk ((α f.1).app _) naturality := by rintro ⟨i, X⟩ ⟨_, _⟩ ⟨f⟩ change SigmaHom.mk _ = SigmaHom.mk _ rw [(α i).naturality] end natTrans end Sigma end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Generator/StrongGenerator.lean
import Mathlib.CategoryTheory.ExtremalEpi import Mathlib.CategoryTheory.Generator.Basic import Mathlib.CategoryTheory.Limits.Presentation /-! # Strong generators If `P : ObjectProperty C`, we say that `P` is a strong generator if it is a generator (in the sense that `IsSeparating P` holds) such that for any proper subobject `A ⊂ X`, there exists a morphism `G ⟶ X` which does not factor through `A` from an object satisfying `P`. The main result is the lemma `isStrongGenerator_iff_exists_extremalEpi` which says that if `P` is `w`-small, `C` is locally `w`-small and has coproducts of size `w`, then `P` is a strong generator iff any object of `C` is the target of an extremal epimorphism from a coproduct of objects satisfying `P`. We also show that if any object in `C` is a colimit of objects in `S`, then `S` is a strong generator. ## References * [Adámek, J. and Rosický, J., *Locally presentable and accessible categories*][Adamek_Rosicky_1994] -/ universe w' w v u namespace CategoryTheory open Limits namespace ObjectProperty variable {C : Type u} [Category.{v} C] (P : ObjectProperty C) /-- A property `P : ObjectProperty C` is a strong generator if it is separating and for any proper subobject `A ⊂ X`, there exists a morphism `G ⟶ X` which does not factor through `A` from an object such that `P G` holds. -/ def IsStrongGenerator : Prop := P.IsSeparating ∧ ∀ ⦃X : C⦄ (A : Subobject X), (∀ (G : C) (_ : P G) (f : G ⟶ X), Subobject.Factors A f) → A = ⊤ variable {P} lemma isStrongGenerator_iff : P.IsStrongGenerator ↔ P.IsSeparating ∧ ∀ ⦃X Y : C⦄ (i : X ⟶ Y) [Mono i], (∀ (G : C) (_ : P G), Function.Surjective (fun (f : G ⟶ X) ↦ f ≫ i)) → IsIso i := by refine ⟨fun ⟨hS₁, hS₂⟩ ↦ ⟨hS₁, fun X Y i _ h ↦ ?_⟩, fun ⟨hS₁, hS₂⟩ ↦ ⟨hS₁, fun X A hA ↦ ?_⟩⟩ · rw [Subobject.isIso_iff_mk_eq_top] refine hS₂ _ (fun G hG g ↦ ?_) rw [Subobject.mk_factors_iff] exact h G hG g · rw [← Subobject.isIso_arrow_iff_eq_top] exact hS₂ A.arrow (fun G hG g ↦ ⟨_, Subobject.factorThru_arrow _ _ (hA G hG g)⟩) namespace IsStrongGenerator section variable (hP : P.IsStrongGenerator) include hP lemma isSeparating : P.IsSeparating := hP.1 lemma subobject_eq_top {X : C} {A : Subobject X} (hA : ∀ (G : C) (_ : P G) (f : G ⟶ X), Subobject.Factors A f) : A = ⊤ := hP.2 _ hA lemma isIso_of_mono ⦃X Y : C⦄ (i : X ⟶ Y) [Mono i] (hi : ∀ (G : C) (_ : P G), Function.Surjective (fun (f : G ⟶ X) ↦ f ≫ i)) : IsIso i := (isStrongGenerator_iff.1 hP).2 i hi lemma exists_of_subobject_ne_top {X : C} {A : Subobject X} (hA : A ≠ ⊤) : ∃ (G : C) (_ : P G) (f : G ⟶ X), ¬ Subobject.Factors A f := by by_contra! exact hA (hP.subobject_eq_top this) lemma exists_of_mono_not_isIso {X Y : C} (i : X ⟶ Y) [Mono i] (hi : ¬ IsIso i) : ∃ (G : C) (_ : P G) (g : G ⟶ Y), ∀ (f : G ⟶ X), f ≫ i ≠ g := by by_contra! exact hi (hP.isIso_of_mono i this) end end IsStrongGenerator namespace IsStrongGenerator lemma mk_of_exists_extremalEpi (hS : ∀ (X : C), ∃ (ι : Type w) (s : ι → C) (_ : ∀ i, P (s i)) (c : Cofan s) (_ : IsColimit c) (p : c.pt ⟶ X), ExtremalEpi p) : P.IsStrongGenerator := by rw [isStrongGenerator_iff] refine ⟨IsSeparating.mk_of_exists_epi.{w} (fun X ↦ ?_), fun X Y i _ hi ↦ ?_⟩ · obtain ⟨ι, s, hs, c, hc, p, _⟩ := hS X exact ⟨ι, s, hs, c, hc, p, inferInstance⟩ · obtain ⟨ι, s, hs, c, hc, p, _⟩ := hS Y replace hi (j : ι) := hi (s j) (hs j) (c.inj j ≫ p) choose φ hφ using hi exact ExtremalEpi.isIso p (Cofan.IsColimit.desc hc φ) _ (Cofan.IsColimit.hom_ext hc _ _ (by simp [hφ])) lemma extremalEpi_coproductFrom (hP : IsStrongGenerator P) (X : C) [HasCoproduct (P.coproductFromFamily X)] : ExtremalEpi (P.coproductFrom X) where toEpi := hP.isSeparating.epi_coproductFrom X isIso p i fac _ := hP.isIso_of_mono _ (fun G hG f ↦ ⟨P.ιCoproductFrom f hG ≫ p, by simp [fac]⟩) end IsStrongGenerator lemma isStrongGenerator_iff_exists_extremalEpi [HasCoproducts.{w} C] [LocallySmall.{w} C] [ObjectProperty.Small.{w} P] : P.IsStrongGenerator ↔ ∀ (X : C), ∃ (ι : Type w) (s : ι → C) (_ : ∀ i, P (s i)) (c : Cofan s) (_ : IsColimit c) (p : c.pt ⟶ X), ExtremalEpi p := by refine ⟨fun hP X ↦ ?_, fun hP ↦ .mk_of_exists_extremalEpi hP⟩ have := hasCoproductsOfShape_of_small.{w} C (CostructuredArrow P.ι X) have := (coproductIsCoproduct (P.coproductFromFamily X)).whiskerEquivalence (Discrete.equivalence (equivShrink.{w} _)).symm refine ⟨_, fun j ↦ ((equivShrink.{w} (CostructuredArrow P.ι X)).symm j).left.1, fun j ↦ ((equivShrink.{w} _).symm j).1.2, _, (coproductIsCoproduct (P.coproductFromFamily X)).whiskerEquivalence (Discrete.equivalence (equivShrink.{w} _)).symm, _, hP.extremalEpi_coproductFrom X⟩ lemma IsStrongGenerator.mk_of_exists_colimitsOfShape (hP : ∀ (X : C), ∃ (J : Type w) (_ : Category.{w'} J), P.colimitsOfShape J X) : P.IsStrongGenerator := by rw [isStrongGenerator_iff] refine ⟨IsSeparating.mk_of_exists_colimitsOfShape hP, fun X Y i _ hi ↦ ?_⟩ suffices IsSplitEpi i by obtain ⟨r, fac⟩ := this exact ⟨r, by simp [← cancel_mono i, fac]⟩ obtain ⟨J, _, ⟨p⟩⟩ := hP Y choose φ hφ using fun j ↦ hi _ (p.prop_diag_obj j) (p.ι.app j) let c : Cocone p.diag := Cocone.mk _ { app := φ naturality j₁ j₂ f := by simp [← cancel_mono i, hφ] } refine ⟨p.isColimit.desc c, p.isColimit.hom_ext (fun j ↦ ?_)⟩ dsimp at hφ ⊢ rw [p.isColimit.fac_assoc, hφ, Category.comp_id] end ObjectProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Generator/HomologicalComplex.lean
import Mathlib.Algebra.Homology.Double import Mathlib.Algebra.Homology.HomologicalComplexLimits import Mathlib.CategoryTheory.Generator.Basic /-! # Generators of the category of homological complexes Let `c : ComplexShape ι` be a complex shape with no loop. If a category `C` has a separator, then `HomologicalComplex C c` has a separating family, and a separator when suitable coproducts exist. -/ universe t w v u open CategoryTheory Limits namespace HomologicalComplex variable {C : Type u} [Category.{v} C] {ι : Type w} (c : ComplexShape ι) [c.HasNoLoop] section variable [HasZeroMorphisms C] [HasZeroObject C] variable {α : Type t} {X : α → C} (hX : ObjectProperty.IsSeparating (.ofObj X)) variable (X) in /-- If `X : α → C` is a separating family, and `c : ComplexShape ι` has no loop, then this is a separating family indexed by `α × ι` in `HomologicalComplex C c`, which consists of homological complexes that are nonzero in at most two (consecutive) degrees. -/ noncomputable def separatingFamily (j : α × ι) : HomologicalComplex C c := evalCompCoyonedaCorepresentative c (X j.1) j.2 include hX in lemma isSeparating_separatingFamily : ObjectProperty.IsSeparating (.ofObj (separatingFamily c X)) := by intro K L f g h ext j apply hX rintro _ ⟨a⟩ p have H := evalCompCoyonedaCorepresentable c (X a) j apply H.homEquiv.symm.injective simpa only [H.homEquiv_symm_comp] using h _ (ObjectProperty.ofObj_apply _ ⟨a, j⟩) (H.homEquiv.symm p) end variable [HasCoproductsOfShape ι C] [Preadditive C] [HasZeroObject C] lemma isSeparator_coproduct_separatingFamily {X : C} (hX : IsSeparator X) : IsSeparator (∐ (fun i ↦ separatingFamily c (fun (_ : Unit) ↦ X) ⟨⟨⟩, i⟩)) := by let φ (i : ι) := separatingFamily c (fun (_ : Unit) ↦ X) ⟨⟨⟩, i⟩ refine isSeparator_of_isColimit_cofan (isSeparating_separatingFamily c (X := fun (_ : Unit) ↦ X) (by simpa using hX)) (c := Cofan.mk (∐ φ) (fun ⟨_, i⟩ ↦ Sigma.ι φ i)) ?_ exact IsColimit.ofWhiskerEquivalence (Discrete.equivalence (Equiv.punitProd.{0} ι).symm) (coproductIsCoproduct φ) instance [HasSeparator C] : HasSeparator (HomologicalComplex C c) := ⟨_, isSeparator_coproduct_separatingFamily c (isSeparator_separator C)⟩ end HomologicalComplex
.lake/packages/mathlib/Mathlib/CategoryTheory/Generator/Abelian.lean
import Mathlib.CategoryTheory.Abelian.Subobject import Mathlib.CategoryTheory.Limits.EssentiallySmall import Mathlib.CategoryTheory.Preadditive.Injective.Basic import Mathlib.CategoryTheory.Generator.Preadditive import Mathlib.CategoryTheory.Abelian.Opposite /-! # A complete abelian category with enough injectives and a separator has an injective coseparator ## Future work * Once we know that Grothendieck categories have enough injectives, we can use this to conclude that Grothendieck categories have an injective coseparator. ## References * [Peter J Freyd, *Abelian Categories* (Theorem 3.37)][freyd1964abelian] -/ open CategoryTheory CategoryTheory.Limits Opposite universe v u namespace CategoryTheory.Abelian variable {C : Type u} [Category.{v} C] [Abelian C] theorem has_injective_coseparator [HasLimits C] [EnoughInjectives C] (G : C) (hG : IsSeparator G) : ∃ G : C, Injective G ∧ IsCoseparator G := by haveI : WellPowered.{v} C := wellPowered_of_isDetector G hG.isDetector haveI : HasProductsOfShape (Subobject (op G)) C := hasProductsOfShape_of_small.{v} _ _ let T : C := Injective.under (piObj fun P : Subobject (op G) => unop P) refine ⟨T, inferInstance, (Preadditive.isCoseparator_iff _).2 fun X Y f hf => ?_⟩ refine (Preadditive.isSeparator_iff _).1 hG _ fun h => ?_ suffices hh : factorThruImage (h ≫ f) = 0 by rw [← Limits.image.fac (h ≫ f), hh, zero_comp] let R := Subobject.mk (factorThruImage (h ≫ f)).op let q₁ : image (h ≫ f) ⟶ unop R := (Subobject.underlyingIso (factorThruImage (h ≫ f)).op).unop.hom let q₂ : unop (R : Cᵒᵖ) ⟶ piObj fun P : Subobject (op G) => unop P := section_ (Pi.π (fun P : Subobject (op G) => (unop P : C)) R) let q : image (h ≫ f) ⟶ T := q₁ ≫ q₂ ≫ Injective.ι _ exact zero_of_comp_mono q (by rw [← Injective.comp_factorThru q (Limits.image.ι (h ≫ f)), Limits.image.fac_assoc, Category.assoc, hf, comp_zero]) theorem has_projective_separator [HasColimits C] [EnoughProjectives C] (G : C) (hG : IsCoseparator G) : ∃ G : C, Projective G ∧ IsSeparator G := by obtain ⟨T, hT₁, hT₂⟩ := has_injective_coseparator (op G) ((isSeparator_op_iff _).2 hG) exact ⟨unop T, inferInstance, (isSeparator_unop_iff _).2 hT₂⟩ end CategoryTheory.Abelian
.lake/packages/mathlib/Mathlib/CategoryTheory/Generator/Presheaf.lean
import Mathlib.CategoryTheory.Generator.Basic import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic /-! # Generators in the category of presheaves In this file, we show that if `A` is a category with zero morphisms that has a separator (and suitable coproducts), then the category of presheaves `Cᵒᵖ ⥤ A` also has a separator. -/ universe w v' v u' u namespace CategoryTheory open Limits Opposite namespace Presheaf variable {C : Type u} [Category.{v} C] {A : Type u'} [Category.{v'} A] [HasCoproducts.{v} A] /-- Given `X : C` and `M : A`, this is the presheaf `Cᵒᵖ ⥤ A` which sends `Y : Cᵒᵖ` to the coproduct of copies of `M` indexed by `Y.unop ⟶ X`. -/ @[simps] noncomputable def freeYoneda (X : C) (M : A) : Cᵒᵖ ⥤ A where obj Y := ∐ (fun (i : (yoneda.obj X).obj Y) ↦ M) map f := Sigma.map' ((yoneda.obj X).map f) (fun _ ↦ 𝟙 M) /-- The bijection `(Presheaf.freeYoneda X M ⟶ F) ≃ (M ⟶ F.obj (op X))`. -/ noncomputable def freeYonedaHomEquiv {X : C} {M : A} {F : Cᵒᵖ ⥤ A} : (freeYoneda X M ⟶ F) ≃ (M ⟶ F.obj (op X)) where toFun f := Sigma.ι (fun (i : (yoneda.obj X).obj _) ↦ M) (𝟙 _) ≫ f.app (op X) invFun g := { app Y := Sigma.desc (fun φ ↦ g ≫ F.map φ.op) naturality _ _ _ := Sigma.hom_ext _ _ (by simp)} left_inv f := by ext Y refine Sigma.hom_ext _ _ (fun φ ↦ ?_) simpa using (Sigma.ι _ (𝟙 _) ≫= f.naturality φ.op).symm right_inv g := by simp @[reassoc] lemma freeYonedaHomEquiv_comp {X : C} {M : A} {F G : Cᵒᵖ ⥤ A} (α : freeYoneda X M ⟶ F) (f : F ⟶ G) : freeYonedaHomEquiv (α ≫ f) = freeYonedaHomEquiv α ≫ f.app (op X) := by simp [freeYonedaHomEquiv] @[reassoc] lemma freeYonedaHomEquiv_symm_comp {X : C} {M : A} {F G : Cᵒᵖ ⥤ A} (α : M ⟶ F.obj (op X)) (f : F ⟶ G) : freeYonedaHomEquiv.symm α ≫ f = freeYonedaHomEquiv.symm (α ≫ f.app (op X)) := by obtain ⟨β, rfl⟩ := freeYonedaHomEquiv.surjective α apply freeYonedaHomEquiv.injective simp only [Equiv.symm_apply_apply, freeYonedaHomEquiv_comp, Equiv.apply_symm_apply] variable (C) lemma isSeparating {ι : Type w} {S : ι → A} (hS : ObjectProperty.IsSeparating (.ofObj S)) : ObjectProperty.IsSeparating (.ofObj (fun (⟨X, i⟩ : C × ι) ↦ freeYoneda X (S i))) := by intro F G f g h ext ⟨X⟩ refine hS _ _ ?_ rintro _ ⟨i⟩ α apply freeYonedaHomEquiv.symm.injective simpa only [freeYonedaHomEquiv_symm_comp] using h _ (ObjectProperty.ofObj_apply _ ⟨X, i⟩) (freeYonedaHomEquiv.symm α) lemma isSeparator {ι : Type w} {S : ι → A} (hS : ObjectProperty.IsSeparating (.ofObj S)) [HasCoproduct (fun (⟨X, i⟩ : C × ι) ↦ freeYoneda X (S i))] [HasZeroMorphisms A] : IsSeparator (∐ (fun (⟨X, i⟩ : C × ι) ↦ freeYoneda X (S i))) := (isSeparating C hS).isSeparator_coproduct variable (A) in instance hasSeparator [HasSeparator A] [HasZeroMorphisms A] [HasCoproducts.{u} A] : HasSeparator (Cᵒᵖ ⥤ A) where hasSeparator := ⟨_, isSeparator C (S := fun (_ : Unit) ↦ separator A) (by simpa using isSeparator_separator A)⟩ end Presheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Generator/Indization.lean
import Mathlib.CategoryTheory.Generator.Basic import Mathlib.CategoryTheory.Limits.Indization.Category import Mathlib.CategoryTheory.Preadditive.Indization /-! # Separating set in the category of ind-objects We construct a separating set in the category of ind-objects and conclude that if `C` is small and additive, then `Ind C` has a separator. -/ universe v u namespace CategoryTheory open Limits section variable {C : Type u} [Category.{v} C] theorem Ind.isSeparating_range_yoneda : ObjectProperty.IsSeparating (.ofObj (Ind.yoneda : C ⥤ _).obj) := by refine fun X Y f g h => (cancel_epi (Ind.colimitPresentationCompYoneda X).hom).1 ?_ exact colimit.hom_ext (fun i => by simp [← Category.assoc, h]) end section variable {C : Type u} [SmallCategory C] [Preadditive C] [HasFiniteColimits C] theorem Ind.isSeparator_range_yoneda : IsSeparator (∐ (Ind.yoneda : C ⥤ _).obj) := Ind.isSeparating_range_yoneda.isSeparator_coproduct end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Generator/Preadditive.lean
import Mathlib.CategoryTheory.Generator.Basic import Mathlib.CategoryTheory.Preadditive.Yoneda.Basic /-! # Separators in preadditive categories This file contains characterizations of separating sets and objects that are valid in all preadditive categories. -/ universe v u open CategoryTheory Opposite ObjectProperty namespace CategoryTheory variable {C : Type u} [Category.{v} C] [Preadditive C] theorem Preadditive.isSeparating_iff (P : ObjectProperty C) : P.IsSeparating ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ (G : C) (_ : P G), ∀ (h : G ⟶ X), h ≫ f = 0) → f = 0 := ⟨fun h𝒢 X Y f hf => h𝒢 _ _ (by simpa only [Limits.comp_zero] using hf), fun h𝒢 X Y f g hfg => sub_eq_zero.1 <| h𝒢 _ (by simpa only [Preadditive.comp_sub, sub_eq_zero] using hfg)⟩ theorem Preadditive.isCoseparating_iff (P : ObjectProperty C) : P.IsCoseparating ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ (G : C) (_ : P G), ∀ (h : Y ⟶ G), f ≫ h = 0) → f = 0 := ⟨fun h𝒢 X Y f hf => h𝒢 _ _ (by simpa only [Limits.zero_comp] using hf), fun h𝒢 X Y f g hfg => sub_eq_zero.1 <| h𝒢 _ (by simpa only [Preadditive.sub_comp, sub_eq_zero] using hfg)⟩ theorem Preadditive.isSeparator_iff (G : C) : IsSeparator G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : G ⟶ X, h ≫ f = 0) → f = 0 := ⟨fun hG X Y f hf => hG.def _ _ (by simpa only [Limits.comp_zero] using hf), fun hG => (isSeparator_def _).2 fun X Y f g hfg => sub_eq_zero.1 <| hG _ (by simpa only [Preadditive.comp_sub, sub_eq_zero] using hfg)⟩ theorem Preadditive.isCoseparator_iff (G : C) : IsCoseparator G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : Y ⟶ G, f ≫ h = 0) → f = 0 := ⟨fun hG X Y f hf => hG.def _ _ (by simpa only [Limits.zero_comp] using hf), fun hG => (isCoseparator_def _).2 fun X Y f g hfg => sub_eq_zero.1 <| hG _ (by simpa only [Preadditive.sub_comp, sub_eq_zero] using hfg)⟩ theorem isSeparator_iff_faithful_preadditiveCoyoneda (G : C) : IsSeparator G ↔ (preadditiveCoyoneda.obj (op G)).Faithful := by rw [isSeparator_iff_faithful_coyoneda_obj, ← whiskering_preadditiveCoyoneda, Functor.comp_obj, Functor.whiskeringRight_obj_obj] exact ⟨fun h => Functor.Faithful.of_comp _ (forget AddCommGrpCat), fun h => Functor.Faithful.comp _ _⟩ theorem isSeparator_iff_faithful_preadditiveCoyonedaObj (G : C) : IsSeparator G ↔ (preadditiveCoyonedaObj G).Faithful := by rw [isSeparator_iff_faithful_preadditiveCoyoneda, preadditiveCoyoneda_obj] exact ⟨fun h => Functor.Faithful.of_comp _ (forget₂ _ AddCommGrpCat.{v}), fun h => Functor.Faithful.comp _ _⟩ theorem isCoseparator_iff_faithful_preadditiveYoneda (G : C) : IsCoseparator G ↔ (preadditiveYoneda.obj G).Faithful := by rw [isCoseparator_iff_faithful_yoneda_obj, ← whiskering_preadditiveYoneda, Functor.comp_obj, Functor.whiskeringRight_obj_obj] exact ⟨fun h => Functor.Faithful.of_comp _ (forget AddCommGrpCat), fun h => Functor.Faithful.comp _ _⟩ theorem isCoseparator_iff_faithful_preadditiveYonedaObj (G : C) : IsCoseparator G ↔ (preadditiveYonedaObj G).Faithful := by rw [isCoseparator_iff_faithful_preadditiveYoneda, preadditiveYoneda_obj] exact ⟨fun h => Functor.Faithful.of_comp _ (forget₂ _ AddCommGrpCat.{v}), fun h => Functor.Faithful.comp _ _⟩ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Generator/Basic.lean
import Mathlib.CategoryTheory.Limits.EssentiallySmall import Mathlib.CategoryTheory.Limits.Shapes.Opposites.Equalizers import Mathlib.CategoryTheory.Subobject.Lattice import Mathlib.CategoryTheory.ObjectProperty.Small import Mathlib.CategoryTheory.ObjectProperty.ColimitsOfShape import Mathlib.CategoryTheory.ObjectProperty.LimitsOfShape import Mathlib.CategoryTheory.Comma.StructuredArrow.Small /-! # Separating and detecting sets There are several non-equivalent notions of a generator of a category. Here, we consider two of them: * We say that `P : ObjectProperty C` is a separating set if the functors `C(G, -)` for `G` such that `P G` are collectively faithful, i.e., if `h ≫ f = h ≫ g` for all `h` with domain satisfying `P` implies `f = g`. * We say that `P : ObjectProperty C` is a detecting set if the functors `C(G, -)` collectively reflect isomorphisms, i.e., if any `h` with domain satisfying `P` uniquely factors through `f`, then `f` is an isomorphism. There are, of course, also the dual notions of coseparating and codetecting sets. ## Main results We * define predicates `IsSeparating`, `IsCoseparating`, `IsDetecting` and `IsCodetecting` on `ObjectProperty C`; * show that equivalences of categories preserves these notions; * show that separating and coseparating are dual notions; * show that detecting and codetecting are dual notions; * show that if `C` has equalizers, then detecting implies separating; * show that if `C` has coequalizers, then codetecting implies coseparating; * show that if `C` is balanced, then separating implies detecting and coseparating implies codetecting; * show that `∅` is separating if and only if `∅` is coseparating if and only if `C` is thin; * show that `∅` is detecting if and only if `∅` is codetecting if and only if `C` is a groupoid; * define predicates `IsSeparator`, `IsCoseparator`, `IsDetector` and `IsCodetector` as the singleton counterparts to the definitions for sets above and restate the above results in this situation; * show that `G` is a separator if and only if `coyoneda.obj (op G)` is faithful (and the dual); * show that `G` is a detector if and only if `coyoneda.obj (op G)` reflects isomorphisms (and the dual); * show that `C` is `WellPowered` if it admits small pullbacks and a detector; * define corresponding typeclasses `HasSeparator`, `HasCoseparator`, `HasDetector` and `HasCodetector` on categories and prove analogous results for these. ## Examples See the files `CategoryTheory.Generator.Presheaf` and `CategoryTheory.Generator.Sheaf`. -/ universe w' w v₁ v₂ u₁ u₂ open CategoryTheory.Limits Opposite namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] namespace ObjectProperty variable (P : ObjectProperty C) /-- We say that `P : ObjectProperty C` is separating if the functors `C(G, -)` for `G : C` such that `P G` are collectively faithful, i.e., if `h ≫ f = h ≫ g` for all `h` with domain in `𝒢` implies `f = g`. -/ def IsSeparating : Prop := ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ (G : C) (_ : P G) (h : G ⟶ X), h ≫ f = h ≫ g) → f = g /-- We say that `P : ObjectProperty C` is coseparating if the functors `C(-, G)` for `G : C` such that `P G` are collectively faithful, i.e., if `f ≫ h = g ≫ h` for all `h` with codomain in `𝒢` implies `f = g`. -/ def IsCoseparating : Prop := ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ (G : C) (_ : P G) (h : Y ⟶ G), f ≫ h = g ≫ h) → f = g /-- We say that `P : ObjectProperty C` is detecting if the functors `C(G, -)` for `G : C` such that `P G` collectively reflect isomorphisms, i.e., if any `h` with domain `G` that `P G` uniquely factors through `f`, then `f` is an isomorphism. -/ def IsDetecting : Prop := ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ (G : C) (_ : P G), ∀ (h : G ⟶ Y), ∃! h' : G ⟶ X, h' ≫ f = h) → IsIso f /-- We say that `P : ObjectProperty C` is codetecting if the functors `C(-, G)` for `G : C` such that `P G` collectively reflect isomorphisms, i.e., if any `h` with codomain `G` such that `P G` uniquely factors through `f`, then `f` is an isomorphism. -/ def IsCodetecting : Prop := ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ (G : C) (_ : P G), ∀ (h : X ⟶ G), ∃! h' : Y ⟶ G, f ≫ h' = h) → IsIso f section Equivalence variable {P} lemma IsSeparating.of_equivalence (h : IsSeparating P) {D : Type*} [Category D] (α : C ≌ D) : IsSeparating (P.strictMap α.functor) := fun X Y f g H => α.inverse.map_injective (h _ _ (fun Z hZ h ↦ by obtain ⟨h', rfl⟩ := (α.toAdjunction.homEquiv _ _).surjective h simp only [Adjunction.homEquiv_unit, Category.assoc, ← Functor.map_comp, H _ (P.strictMap_obj _ hZ) h'])) lemma IsCoseparating.of_equivalence (h : IsCoseparating P) {D : Type*} [Category D] (α : C ≌ D) : IsCoseparating (P.strictMap α.functor) := fun X Y f g H => α.inverse.map_injective (h _ _ (fun Z hZ h ↦ by obtain ⟨h', rfl⟩ := (α.symm.toAdjunction.homEquiv _ _).symm.surjective h simp only [Equivalence.symm_inverse, Equivalence.symm_functor, Adjunction.homEquiv_counit, ← Functor.map_comp_assoc, H _ (P.strictMap_obj _ hZ) h'])) end Equivalence section Dual theorem isSeparating_op_iff : IsSeparating P.op ↔ IsCoseparating P := by refine ⟨fun hP X Y f g hfg => ?_, fun hP X Y f g hfg => ?_⟩ · refine Quiver.Hom.op_inj (hP _ _ fun G hG h => Quiver.Hom.unop_inj ?_) simpa only [unop_comp, Quiver.Hom.unop_op] using hfg _ hG _ · refine Quiver.Hom.unop_inj (hP _ _ fun G hG h => Quiver.Hom.op_inj ?_) simpa only [op_comp, Quiver.Hom.op_unop] using hfg _ hG _ theorem isCoseparating_op_iff : IsCoseparating P.op ↔ IsSeparating P := by refine ⟨fun hP X Y f g hfg => ?_, fun hP X Y f g hfg => ?_⟩ · refine Quiver.Hom.op_inj (hP _ _ fun G hG h => Quiver.Hom.unop_inj ?_) simpa only [unop_comp, Quiver.Hom.unop_op] using hfg _ hG _ · refine Quiver.Hom.unop_inj (hP _ _ fun G hG h => Quiver.Hom.op_inj ?_) simpa only [op_comp, Quiver.Hom.op_unop] using hfg _ hG _ theorem isCoseparating_unop_iff (P : ObjectProperty Cᵒᵖ) : IsCoseparating P.unop ↔ IsSeparating P := P.unop.isSeparating_op_iff.symm theorem isSeparating_unop_iff (P : ObjectProperty Cᵒᵖ) : IsSeparating P.unop ↔ IsCoseparating P := P.unop.isCoseparating_op_iff.symm theorem isDetecting_op_iff : IsDetecting P.op ↔ IsCodetecting P := by refine ⟨fun hP X Y f hf => ?_, fun hP X Y f hf => ?_⟩ · refine (isIso_op_iff _).1 (hP _ fun G hG h => ?_) obtain ⟨t, ht, ht'⟩ := hf (unop G) hG h.unop exact ⟨t.op, Quiver.Hom.unop_inj ht, fun y hy => Quiver.Hom.unop_inj (ht' _ (Quiver.Hom.op_inj hy))⟩ · refine (isIso_unop_iff _).1 (hP _ fun G hG h => ?_) obtain ⟨t, ht, ht'⟩ := hf (op G) hG h.op refine ⟨t.unop, Quiver.Hom.op_inj ht, fun y hy => Quiver.Hom.op_inj (ht' _ ?_)⟩ exact Quiver.Hom.unop_inj (by simpa only using hy) theorem isCodetecting_op_iff : IsCodetecting P.op ↔ IsDetecting P := by refine ⟨fun hP X Y f hf => ?_, fun hP X Y f hf => ?_⟩ · refine (isIso_op_iff _).1 (hP _ fun G hG h => ?_) obtain ⟨t, ht, ht'⟩ := hf (unop G) hG h.unop exact ⟨t.op, Quiver.Hom.unop_inj ht, fun y hy => Quiver.Hom.unop_inj (ht' _ (Quiver.Hom.op_inj hy))⟩ · refine (isIso_unop_iff _).1 (hP _ fun G hG h => ?_) obtain ⟨t, ht, ht'⟩ := hf (op G) hG h.op refine ⟨t.unop, Quiver.Hom.op_inj ht, fun y hy => Quiver.Hom.op_inj (ht' _ ?_)⟩ exact Quiver.Hom.unop_inj (by simpa only using hy) theorem isDetecting_unop_iff (P : ObjectProperty Cᵒᵖ) : IsDetecting P.unop ↔ IsCodetecting P := P.unop.isCodetecting_op_iff.symm theorem isCodetecting_unop_iff (P : ObjectProperty Cᵒᵖ) : IsCodetecting P.unop ↔ IsDetecting P := P.unop.isDetecting_op_iff.symm end Dual variable {P} theorem IsDetecting.isSeparating [HasEqualizers C] (hP : IsDetecting P) : IsSeparating P := fun _ _ f g hfg => have : IsIso (equalizer.ι f g) := hP _ fun _ hG _ => equalizer.existsUnique _ (hfg _ hG _) eq_of_epi_equalizer theorem IsCodetecting.isCoseparating [HasCoequalizers C] : IsCodetecting P → IsCoseparating P := by simpa only [← isSeparating_op_iff, ← isDetecting_op_iff] using IsDetecting.isSeparating theorem IsSeparating.isDetecting [Balanced C] (hP : IsSeparating P) : IsDetecting P := by intro X Y f hf refine (isIso_iff_mono_and_epi _).2 ⟨⟨fun g h hgh => hP _ _ fun G hG i => ?_⟩, ⟨fun g h hgh => ?_⟩⟩ · obtain ⟨t, -, ht⟩ := hf G hG (i ≫ g ≫ f) rw [ht (i ≫ g) (Category.assoc _ _ _), ht (i ≫ h) (hgh.symm ▸ Category.assoc _ _ _)] · refine hP _ _ fun G hG i => ?_ obtain ⟨t, rfl, -⟩ := hf G hG i rw [Category.assoc, hgh, Category.assoc] lemma IsDetecting.isIso_iff_of_mono (hP : IsDetecting P) {X Y : C} (f : X ⟶ Y) [Mono f] : IsIso f ↔ ∀ (G : C) (_ : P G), Function.Surjective ((coyoneda.obj (op G)).map f) := by constructor · intro h rw [isIso_iff_yoneda_map_bijective] at h intro A _ exact (h A).2 · intro hf refine hP _ (fun A hA g ↦ existsUnique_of_exists_of_unique ?_ ?_) · exact hf A hA g · intro l₁ l₂ h₁ h₂ rw [← cancel_mono f, h₁, h₂] lemma IsCodetecting.isIso_iff_of_epi (hP : IsCodetecting P) {X Y : C} (f : X ⟶ Y) [Epi f] : IsIso f ↔ ∀ (G : C) (_ : P G), Function.Surjective ((yoneda.obj G).map f.op) := by constructor · intro h rw [isIso_iff_coyoneda_map_bijective] at h intro A _ exact (h A).2 · intro hf refine hP _ (fun A hA g ↦ existsUnique_of_exists_of_unique ?_ ?_) · exact hf A hA g · intro l₁ l₂ h₁ h₂ rw [← cancel_epi f, h₁, h₂] section attribute [local instance] balanced_opposite theorem IsCoseparating.isCodetecting [Balanced C] : IsCoseparating P → IsCodetecting P := by simpa only [← isDetecting_op_iff, ← isSeparating_op_iff] using IsSeparating.isDetecting end theorem isDetecting_iff_isSeparating [HasEqualizers C] [Balanced C] : IsDetecting P ↔ IsSeparating P := ⟨IsDetecting.isSeparating, IsSeparating.isDetecting⟩ theorem isCodetecting_iff_isCoseparating [HasCoequalizers C] [Balanced C] : IsCodetecting P ↔ IsCoseparating P := ⟨IsCodetecting.isCoseparating, IsCoseparating.isCodetecting⟩ section Mono theorem IsSeparating.of_le (hP : IsSeparating P) {Q : ObjectProperty C} (h : P ≤ Q) : IsSeparating Q := fun _ _ _ _ hfg => hP _ _ fun _ hG _ => hfg _ (h _ hG) _ theorem IsCoseparating.of_le (hP : IsCoseparating P) {Q : ObjectProperty C} (h : P ≤ Q) : IsCoseparating Q := fun _ _ _ _ hfg => hP _ _ fun _ hG _ => hfg _ (h _ hG) _ theorem IsDetecting.of_le (hP : IsDetecting P) {Q : ObjectProperty C} (h : P ≤ Q) : IsDetecting Q := fun _ _ _ hf => hP _ fun _ hG _ => hf _ (h _ hG) _ theorem IsCodetecting.of_le (h𝒢 : IsCodetecting P) {Q : ObjectProperty C} (h : P ≤ Q) : IsCodetecting Q := fun _ _ _ hf => h𝒢 _ fun _ hG _ => hf _ (h _ hG) _ end Mono section Empty lemma isThin_of_isSeparating_bot (h : IsSeparating (⊥ : ObjectProperty C)) : Quiver.IsThin C := fun _ _ ↦ ⟨fun _ _ ↦ h _ _ (by simp)⟩ lemma isSeparating_bot_of_isThin [Quiver.IsThin C] : IsSeparating (⊥ : ObjectProperty C) := fun _ _ _ _ _ ↦ Subsingleton.elim _ _ lemma isThin_of_isCoseparating_bot (h : IsCoseparating (⊥ : ObjectProperty C)) : Quiver.IsThin C := fun _ _ ↦ ⟨fun _ _ ↦ h _ _ (by simp)⟩ lemma isCoseparating_bot_of_isThin [Quiver.IsThin C] : IsCoseparating (⊥ : ObjectProperty C) := fun _ _ _ _ _ ↦ Subsingleton.elim _ _ lemma isGroupoid_of_isDetecting_bot (h : IsDetecting (⊥ : ObjectProperty C)) : IsGroupoid C where all_isIso f := h _ (by simp) lemma isDetecting_bot_of_isGroupoid [IsGroupoid C] : IsDetecting (⊥ : ObjectProperty C) := fun _ _ _ _ ↦ inferInstance lemma isGroupoid_of_isCodetecting_bot (h : IsCodetecting (⊥ : ObjectProperty C)) : IsGroupoid C where all_isIso f := h _ (by simp) lemma isCodetecting_bot_of_isGroupoid [IsGroupoid C] : IsCodetecting (⊥ : ObjectProperty C) := fun _ _ _ _ ↦ inferInstance end Empty lemma IsSeparating.mk_of_exists_epi (hP : ∀ (X : C), ∃ (ι : Type w) (s : ι → C) (_ : ∀ i, P (s i)) (c : Cofan s) (_ : IsColimit c) (p : c.pt ⟶ X), Epi p) : P.IsSeparating := by intro X Y f g h obtain ⟨ι, s, hs, c, hc, p, _⟩ := hP X rw [← cancel_epi p] exact Cofan.IsColimit.hom_ext hc _ _ (fun i ↦ by simpa using h _ (hs i) (c.inj i ≫ p)) lemma IsCoseparating.mk_of_exists_mono (hP : ∀ (X : C), ∃ (ι : Type w) (s : ι → C) (_ : ∀ i, P (s i)) (c : Fan s) (_ : IsLimit c) (j : X ⟶ c.pt), Mono j) : P.IsCoseparating := by intro X Y f g h obtain ⟨ι, s, hs, c, hc, j, _⟩ := hP Y rw [← cancel_mono j] exact Fan.IsLimit.hom_ext hc _ _ (fun i ↦ by simpa using h _ (hs i) (j ≫ c.proj i)) lemma IsSeparating.mk_of_exists_colimitsOfShape (hP : ∀ (X : C), ∃ (J : Type w) (_ : Category.{w'} J), P.colimitsOfShape J X) : P.IsSeparating := by intro X Y f g h obtain ⟨J, _, ⟨p⟩⟩ := hP X exact p.isColimit.hom_ext (fun j ↦ h _ (p.prop_diag_obj _) _) lemma IsCoseparating.mk_of_exists_limitsOfShape (hP : ∀ (X : C), ∃ (J : Type w) (_ : Category.{w'} J), P.limitsOfShape J X) : P.IsCoseparating := by intro X Y f g h obtain ⟨J, _, ⟨p⟩⟩ := hP Y exact p.isLimit.hom_ext (fun j ↦ h _ (p.prop_diag_obj _) _) variable (P) section /-- Given `P : ObjectProperty C` and `X : C`, this is the map which sends `i : CostructuredArrow P.ι X` to `i.left.obj : C`. The coproduct of this family is the source of the morphism `P.coproductFrom X`. -/ abbrev coproductFromFamily (X : C) (i : CostructuredArrow P.ι X) : C := i.left.obj variable (X : C) variable [HasCoproduct (P.coproductFromFamily X)] /-- Given `P : ObjectProperty C` and `X : C`, this is the coproduct of all the morphisms `Y ⟶ X` such that `P Y` holds. -/ noncomputable abbrev coproductFrom : ∐ (P.coproductFromFamily X) ⟶ X := Sigma.desc (fun i ↦ i.hom) variable {X} in /-- The inclusion morphisms to `∐ (P.coproductFromFamily X)`. -/ noncomputable abbrev ιCoproductFrom {Y : C} (f : Y ⟶ X) (hY : P Y) : Y ⟶ ∐ (P.coproductFromFamily X) := by exact Sigma.ι (P.coproductFromFamily X) (CostructuredArrow.mk (Y := ⟨Y, hY⟩) (by exact f)) end variable {P} in lemma IsSeparating.epi_coproductFrom (hP : P.IsSeparating) (X : C) [HasCoproduct (P.coproductFromFamily X)] : Epi (P.coproductFrom X) where left_cancellation u v huv := hP _ _ (fun G hG h ↦ by simpa using P.ιCoproductFrom h hG ≫= huv) theorem isSeparating_iff_epi [∀ (X : C), HasCoproduct (P.coproductFromFamily X)] : IsSeparating P ↔ ∀ X : C, Epi (P.coproductFrom X) := ⟨fun hP X ↦ hP.epi_coproductFrom X, fun hP ↦ IsSeparating.mk_of_exists_epi (fun X ↦ ⟨_, P.coproductFromFamily X, fun i ↦ i.left.2, _, colimit.isColimit _, _, hP X⟩)⟩ section /-- Given `P : ObjectProperty C` and `X : C`, this is the map which sends `i : StructuredArrow P.ι X` to `i.right.obj : C`. The product of this family is the target of the morphism `P.productTo X`. -/ abbrev productToFamily (X : C) (i : StructuredArrow X P.ι) : C := i.right.obj variable (X : C) variable [HasProduct (P.productToFamily X)] /-- Given `P : ObjectProperty C` and `X : C`, this is the product of all the morphisms `X ⟶ Y` such that `P Y` holds. -/ noncomputable abbrev productTo : X ⟶ ∏ᶜ (P.productToFamily X) := Pi.lift (fun i ↦ i.hom) variable {X} in /-- The projection morphisms from `∏ᶜ (P.productToFamily X)`. -/ noncomputable abbrev πProductTo {Y : C} (f : X ⟶ Y) (hY : P Y) : ∏ᶜ (P.productToFamily X) ⟶ Y := by exact Pi.π (P.productToFamily X) (StructuredArrow.mk (Y := ⟨Y, hY⟩) (by exact f)) end variable {P} in lemma IsCoseparating.mono_productTo (hP : P.IsCoseparating) (X : C) [HasProduct (P.productToFamily X)] : Mono (P.productTo X) where right_cancellation u v huv := hP _ _ (fun G hG h ↦ by simpa using huv =≫ P.πProductTo h hG) theorem isCoseparating_iff_mono [∀ (X : C), HasProduct (P.productToFamily X)] : IsCoseparating P ↔ ∀ X : C, Mono (P.productTo X) := ⟨fun hP X ↦ hP.mono_productTo X, fun hP ↦ IsCoseparating.mk_of_exists_mono (fun X ↦ ⟨_, P.productToFamily X, fun i ↦ i.right.2, _, limit.isLimit _, _, hP X⟩)⟩ end ObjectProperty /-- An ingredient of the proof of the Special Adjoint Functor Theorem: a complete well-powered category with a small coseparating set has an initial object. In fact, it follows from the Special Adjoint Functor Theorem that `C` is already cocomplete, see `hasColimits_of_hasLimits_of_isCoseparating`. -/ theorem hasInitial_of_isCoseparating [LocallySmall.{w} C] [WellPowered.{w} C] [HasLimitsOfSize.{w, w} C] {P : ObjectProperty C} [ObjectProperty.Small.{w} P] (hP : P.IsCoseparating) : HasInitial C := by have := hasFiniteLimits_of_hasLimitsOfSize C haveI := hasProductsOfShape_of_small C (Subtype P) haveI := fun A => hasProductsOfShape_of_small.{w} C (StructuredArrow A P.ι) letI := completeLatticeOfCompleteSemilatticeInf (Subobject (piObj (Subtype.val : Subtype P → C))) suffices ∀ A : C, Unique (((⊥ : Subobject (piObj (Subtype.val : Subtype P → C))) : C) ⟶ A) by exact hasInitial_of_unique ((⊥ : Subobject (piObj (Subtype.val : Subtype P → C))) : C) have := hP.mono_productTo refine fun A => ⟨⟨?_⟩, fun f => ?_⟩ · let s : ∏ᶜ (Subtype.val (p := P)) ⟶ ∏ᶜ P.productToFamily A := Pi.lift (fun f ↦ Pi.π Subtype.val ⟨f.right.obj, f.right.property⟩) exact Subobject.ofLEMk _ (pullback.fst _ _ : pullback s (P.productTo A) ⟶ _) bot_le ≫ pullback.snd _ _ · suffices ∀ (g : Subobject.underlying.obj ⊥ ⟶ A), f = g by apply this intro g suffices IsSplitEpi (equalizer.ι f g) by exact eq_of_epi_equalizer exact IsSplitEpi.mk' ⟨Subobject.ofLEMk _ (equalizer.ι f g ≫ Subobject.arrow _) bot_le, by ext simp⟩ /-- An ingredient of the proof of the Special Adjoint Functor Theorem: a cocomplete well-copowered category with a small separating set has a terminal object. In fact, it follows from the Special Adjoint Functor Theorem that `C` is already complete, see `hasLimits_of_hasColimits_of_isSeparating`. -/ theorem hasTerminal_of_isSeparating [LocallySmall.{w} Cᵒᵖ] [WellPowered.{w} Cᵒᵖ] [HasColimitsOfSize.{w, w} C] {P : ObjectProperty C} [ObjectProperty.Small.{w} P] (hP : P.IsSeparating) : HasTerminal C := by haveI : HasInitial Cᵒᵖ := hasInitial_of_isCoseparating (P.isCoseparating_op_iff.2 hP) exact hasTerminal_of_hasInitial_op section WellPowered namespace Subobject theorem eq_of_le_of_isDetecting {𝒢 : ObjectProperty C} (h𝒢 : 𝒢.IsDetecting) {X : C} (P Q : Subobject X) (h₁ : P ≤ Q) (h₂ : ∀ (G : C) (_ : 𝒢 G), ∀ {f : G ⟶ X}, Q.Factors f → P.Factors f) : P = Q := by suffices IsIso (ofLE _ _ h₁) by exact le_antisymm h₁ (le_of_comm (inv (ofLE _ _ h₁)) (by simp)) refine h𝒢 _ fun G hG f => ?_ have : P.Factors (f ≫ Q.arrow) := h₂ _ hG ((factors_iff _ _).2 ⟨_, rfl⟩) refine ⟨factorThru _ _ this, ?_, fun g (hg : g ≫ _ = f) => ?_⟩ · simp only [← cancel_mono Q.arrow, Category.assoc, ofLE_arrow, factorThru_arrow] · simp only [← cancel_mono (Subobject.ofLE _ _ h₁), ← cancel_mono Q.arrow, hg, Category.assoc, ofLE_arrow, factorThru_arrow] theorem inf_eq_of_isDetecting [HasPullbacks C] {𝒢 : ObjectProperty C} (h𝒢 : 𝒢.IsDetecting) {X : C} (P Q : Subobject X) (h : ∀ (G : C) (_ : 𝒢 G), ∀ {f : G ⟶ X}, P.Factors f → Q.Factors f) : P ⊓ Q = P := eq_of_le_of_isDetecting h𝒢 _ _ _root_.inf_le_left fun _ hG _ hf => (inf_factors _).2 ⟨hf, h _ hG hf⟩ theorem eq_of_isDetecting [HasPullbacks C] {𝒢 : ObjectProperty C} (h𝒢 : 𝒢.IsDetecting) {X : C} (P Q : Subobject X) (h : ∀ (G : C) (_ : 𝒢 G), ∀ {f : G ⟶ X}, P.Factors f ↔ Q.Factors f) : P = Q := calc P = P ⊓ Q := Eq.symm <| inf_eq_of_isDetecting h𝒢 _ _ fun G hG _ hf => (h G hG).1 hf _ = Q ⊓ P := inf_comm .. _ = Q := inf_eq_of_isDetecting h𝒢 _ _ fun G hG _ hf => (h G hG).2 hf end Subobject /-- A category with pullbacks and a small detecting set is well-powered. -/ theorem wellPowered_of_isDetecting [HasPullbacks C] {𝒢 : ObjectProperty C} [ObjectProperty.Small.{w} 𝒢] [LocallySmall.{w} C] (h𝒢 : 𝒢.IsDetecting) : WellPowered.{w} C where subobject_small X := small_of_injective (f := fun P : Subobject X => { f : Σ G : Subtype 𝒢, G.1 ⟶ X | P.Factors f.2 }) fun P Q h => Subobject.eq_of_isDetecting h𝒢 _ _ (by simpa [Set.ext_iff, Sigma.forall] using h) end WellPowered namespace StructuredArrow variable (S : D) (T : C ⥤ D) theorem isCoseparating_inverseImage_proj {P : ObjectProperty C} (hP : P.IsCoseparating) : (P.inverseImage (proj S T)).IsCoseparating := by refine fun X Y f g hfg => ext _ _ (hP _ _ fun G hG h => ?_) exact congr_arg CommaMorphism.right (hfg (mk (Y.hom ≫ T.map h)) hG (homMk h rfl)) end StructuredArrow namespace CostructuredArrow variable (S : C ⥤ D) (T : D) theorem isSeparating_inverseImage_proj {P : ObjectProperty C} (hP : P.IsSeparating) : (P.inverseImage (proj S T)).IsSeparating := by refine fun X Y f g hfg => ext _ _ (hP _ _ fun G hG h => ?_) exact congr_arg CommaMorphism.left (hfg (mk (S.map h ≫ X.hom)) hG (homMk h rfl)) end CostructuredArrow /-- We say that `G` is a separator if the functor `C(G, -)` is faithful. -/ def IsSeparator (G : C) : Prop := ObjectProperty.IsSeparating (.singleton G) /-- We say that `G` is a coseparator if the functor `C(-, G)` is faithful. -/ def IsCoseparator (G : C) : Prop := ObjectProperty.IsCoseparating (.singleton G) /-- We say that `G` is a detector if the functor `C(G, -)` reflects isomorphisms. -/ def IsDetector (G : C) : Prop := ObjectProperty.IsDetecting (.singleton G) /-- We say that `G` is a codetector if the functor `C(-, G)` reflects isomorphisms. -/ def IsCodetector (G : C) : Prop := ObjectProperty.IsCodetecting (.singleton G) section Equivalence theorem IsSeparator.of_equivalence {G : C} (h : IsSeparator G) (α : C ≌ D) : IsSeparator (α.functor.obj G) := by simpa using ObjectProperty.IsSeparating.of_equivalence h α theorem IsCoseparator.of_equivalence {G : C} (h : IsCoseparator G) (α : C ≌ D) : IsCoseparator (α.functor.obj G) := by simpa using ObjectProperty.IsCoseparating.of_equivalence h α end Equivalence section Dual open ObjectProperty theorem isSeparator_op_iff (G : C) : IsSeparator (op G) ↔ IsCoseparator G := by rw [IsSeparator, IsCoseparator, ← isSeparating_op_iff, op_singleton] theorem isCoseparator_op_iff (G : C) : IsCoseparator (op G) ↔ IsSeparator G := by rw [IsSeparator, IsCoseparator, ← isCoseparating_op_iff, op_singleton] theorem isCoseparator_unop_iff (G : Cᵒᵖ) : IsCoseparator (unop G) ↔ IsSeparator G := by rw [IsSeparator, IsCoseparator, ← isCoseparating_unop_iff, unop_singleton] theorem isSeparator_unop_iff (G : Cᵒᵖ) : IsSeparator (unop G) ↔ IsCoseparator G := by rw [IsSeparator, IsCoseparator, ← isSeparating_unop_iff, unop_singleton] theorem isDetector_op_iff (G : C) : IsDetector (op G) ↔ IsCodetector G := by rw [IsDetector, IsCodetector, ← isDetecting_op_iff, op_singleton] theorem isCodetector_op_iff (G : C) : IsCodetector (op G) ↔ IsDetector G := by rw [IsDetector, IsCodetector, ← isCodetecting_op_iff, op_singleton] theorem isCodetector_unop_iff (G : Cᵒᵖ) : IsCodetector (unop G) ↔ IsDetector G := by rw [IsDetector, IsCodetector, ← isCodetecting_unop_iff, unop_singleton] theorem isDetector_unop_iff (G : Cᵒᵖ) : IsDetector (unop G) ↔ IsCodetector G := by rw [IsDetector, IsCodetector, ← isDetecting_unop_iff, unop_singleton] end Dual theorem IsDetector.isSeparator [HasEqualizers C] {G : C} : IsDetector G → IsSeparator G := ObjectProperty.IsDetecting.isSeparating theorem IsCodetector.isCoseparator [HasCoequalizers C] {G : C} : IsCodetector G → IsCoseparator G := ObjectProperty.IsCodetecting.isCoseparating theorem IsSeparator.isDetector [Balanced C] {G : C} : IsSeparator G → IsDetector G := ObjectProperty.IsSeparating.isDetecting theorem IsCoseparator.isCodetector [Balanced C] {G : C} : IsCoseparator G → IsCodetector G := ObjectProperty.IsCoseparating.isCodetecting theorem isSeparator_def (G : C) : IsSeparator G ↔ ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : G ⟶ X, h ≫ f = h ≫ g) → f = g := ⟨fun hG X Y f g hfg => hG _ _ fun H hH h => by obtain rfl := (ObjectProperty.singleton_iff _ _).1 hH exact hfg h, fun hG _ _ _ _ hfg => hG _ _ fun _ => hfg _ (by simp) _⟩ theorem IsSeparator.def {G : C} : IsSeparator G → ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : G ⟶ X, h ≫ f = h ≫ g) → f = g := (isSeparator_def _).1 theorem isCoseparator_def (G : C) : IsCoseparator G ↔ ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : Y ⟶ G, f ≫ h = g ≫ h) → f = g := ⟨fun hG X Y f g hfg => hG _ _ fun H hH h => by obtain rfl := (ObjectProperty.singleton_iff _ _).1 hH exact hfg h, fun hG _ _ _ _ hfg => hG _ _ fun _ => hfg _ (by simp) _⟩ theorem IsCoseparator.def {G : C} : IsCoseparator G → ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : Y ⟶ G, f ≫ h = g ≫ h) → f = g := (isCoseparator_def _).1 theorem isDetector_def (G : C) : IsDetector G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : G ⟶ Y, ∃! h', h' ≫ f = h) → IsIso f := ⟨fun hG X Y f hf => hG _ fun H hH h => by obtain rfl := (ObjectProperty.singleton_iff _ _).1 hH exact hf h, fun hG _ _ _ hf => hG _ fun _ => hf _ (by simp) _⟩ theorem IsDetector.def {G : C} : IsDetector G → ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : G ⟶ Y, ∃! h', h' ≫ f = h) → IsIso f := (isDetector_def _).1 theorem isCodetector_def (G : C) : IsCodetector G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : X ⟶ G, ∃! h', f ≫ h' = h) → IsIso f := ⟨fun hG X Y f hf => hG _ fun H hH h => by obtain rfl := (ObjectProperty.singleton_iff _ _).1 hH exact hf h, fun hG _ _ _ hf => hG _ fun _ => hf _ (by simp) _⟩ theorem IsCodetector.def {G : C} : IsCodetector G → ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : X ⟶ G, ∃! h', f ≫ h' = h) → IsIso f := (isCodetector_def _).1 theorem isSeparator_iff_faithful_coyoneda_obj (G : C) : IsSeparator G ↔ (coyoneda.obj (op G)).Faithful := ⟨fun hG => ⟨fun hfg => hG.def _ _ (congr_fun hfg)⟩, fun _ => (isSeparator_def _).2 fun _ _ _ _ hfg => (coyoneda.obj (op G)).map_injective (funext hfg)⟩ theorem isCoseparator_iff_faithful_yoneda_obj (G : C) : IsCoseparator G ↔ (yoneda.obj G).Faithful := ⟨fun hG => ⟨fun hfg => Quiver.Hom.unop_inj (hG.def _ _ (congr_fun hfg))⟩, fun _ => (isCoseparator_def _).2 fun _ _ _ _ hfg => Quiver.Hom.op_inj <| (yoneda.obj G).map_injective (funext hfg)⟩ theorem isSeparator_iff_epi (G : C) [∀ A : C, HasCoproduct fun _ : G ⟶ A => G] : IsSeparator G ↔ ∀ A : C, Epi (Sigma.desc fun f : G ⟶ A => f) := by rw [isSeparator_def] refine ⟨fun h A => ⟨fun u v huv => h _ _ fun i => ?_⟩, fun h X Y f g hh => ?_⟩ · simpa using Sigma.ι _ i ≫= huv · haveI := h X refine (cancel_epi (Sigma.desc fun f : G ⟶ X => f)).1 (colimit.hom_ext fun j => ?_) simpa using hh j.as theorem isCoseparator_iff_mono (G : C) [∀ A : C, HasProduct fun _ : A ⟶ G => G] : IsCoseparator G ↔ ∀ A : C, Mono (Pi.lift fun f : A ⟶ G => f) := by rw [isCoseparator_def] refine ⟨fun h A => ⟨fun u v huv => h _ _ fun i => ?_⟩, fun h X Y f g hh => ?_⟩ · simpa using huv =≫ Pi.π _ i · haveI := h Y refine (cancel_mono (Pi.lift fun f : Y ⟶ G => f)).1 (limit.hom_ext fun j => ?_) simpa using hh j.as section ZeroMorphisms variable [HasZeroMorphisms C] lemma isSeparator_of_isColimit_cofan {β : Type w} {f : β → C} (hf : ObjectProperty.IsSeparating (.ofObj f)) {c : Cofan f} (hc : IsColimit c) : IsSeparator c.pt := by rw [isSeparator_def] refine fun _ _ _ _ huv ↦ hf _ _ (fun _ h g ↦ ?_) obtain ⟨b⟩ := h classical simpa using c.inj b ≫= huv (hc.desc (Cofan.mk _ (Pi.single b g))) lemma isSeparator_iff_of_isColimit_cofan {β : Type w} {f : β → C} {c : Cofan f} (hc : IsColimit c) : IsSeparator c.pt ↔ ObjectProperty.IsSeparating (.ofObj f) := by refine ⟨fun h X Y u v huv => ?_, fun h => isSeparator_of_isColimit_cofan h hc⟩ refine h.def _ _ fun g => hc.hom_ext fun b => ?_ simpa using huv (f b.as) (by simp) (c.inj _ ≫ g) theorem isSeparator_sigma {β : Type w} (f : β → C) [HasCoproduct f] : IsSeparator (∐ f) ↔ ObjectProperty.IsSeparating (.ofObj f) := isSeparator_iff_of_isColimit_cofan (hc := colimit.isColimit _) theorem isSeparator_coprod (G H : C) [HasBinaryCoproduct G H] : IsSeparator (G ⨿ H) ↔ ObjectProperty.IsSeparating (.pair G H) := by refine (isSeparator_iff_of_isColimit_cofan (coprodIsCoprod G H)).trans ?_ convert Iff.rfl ext X simp only [ObjectProperty.pair_iff, ObjectProperty.ofObj_iff] constructor · rintro (rfl | rfl); exacts [⟨.left, rfl⟩, ⟨.right, rfl⟩] · rintro ⟨⟨_ | _⟩, rfl⟩ <;> tauto theorem isSeparator_coprod_of_isSeparator_left (G H : C) [HasBinaryCoproduct G H] (hG : IsSeparator G) : IsSeparator (G ⨿ H) := (isSeparator_coprod _ _).2 <| ObjectProperty.IsSeparating.of_le hG <| by simp theorem isSeparator_coprod_of_isSeparator_right (G H : C) [HasBinaryCoproduct G H] (hH : IsSeparator H) : IsSeparator (G ⨿ H) := (isSeparator_coprod _ _).2 <| ObjectProperty.IsSeparating.of_le hH <| by simp theorem ObjectProperty.IsSeparating.isSeparator_coproduct {β : Type w} {f : β → C} [HasCoproduct f] (hS : ObjectProperty.IsSeparating (.ofObj f)) : IsSeparator (∐ f) := (isSeparator_sigma _).2 hS theorem isSeparator_sigma_of_isSeparator {β : Type w} (f : β → C) [HasCoproduct f] (b : β) (hb : IsSeparator (f b)) : IsSeparator (∐ f) := (isSeparator_sigma _).2 <| ObjectProperty.IsSeparating.of_le hb <| by simp lemma isCoseparator_of_isLimit_fan {β : Type w} {f : β → C} (hf : ObjectProperty.IsCoseparating (.ofObj f)) {c : Fan f} (hc : IsLimit c) : IsCoseparator c.pt := by rw [isCoseparator_def] refine fun _ _ _ _ huv ↦ hf _ _ (fun _ h g ↦ ?_) obtain ⟨b⟩ := h classical simpa using huv (hc.lift (Fan.mk _ (Pi.single b g))) =≫ c.proj b lemma isCoseparator_iff_of_isLimit_fan {β : Type w} {f : β → C} {c : Fan f} (hc : IsLimit c) : IsCoseparator c.pt ↔ ObjectProperty.IsCoseparating (.ofObj f) := by refine ⟨fun h X Y u v huv => ?_, fun h => isCoseparator_of_isLimit_fan h hc⟩ refine h.def _ _ fun g => hc.hom_ext fun b => ?_ simpa using huv (f b.as) (by simp) (g ≫ c.proj _) theorem isCoseparator_pi {β : Type w} (f : β → C) [HasProduct f] : IsCoseparator (∏ᶜ f) ↔ ObjectProperty.IsCoseparating (.ofObj f) := isCoseparator_iff_of_isLimit_fan (hc := limit.isLimit _) theorem isCoseparator_prod (G H : C) [HasBinaryProduct G H] : IsCoseparator (G ⨯ H) ↔ ObjectProperty.IsCoseparating (.pair G H) := by refine (isCoseparator_iff_of_isLimit_fan (prodIsProd G H)).trans ?_ convert Iff.rfl ext X simp only [ObjectProperty.pair_iff, ObjectProperty.ofObj_iff] constructor · rintro (rfl | rfl); exacts [⟨.left, rfl⟩, ⟨.right, rfl⟩] · rintro ⟨⟨_ | _⟩, rfl⟩ <;> tauto theorem isCoseparator_prod_of_isCoseparator_left (G H : C) [HasBinaryProduct G H] (hG : IsCoseparator G) : IsCoseparator (G ⨯ H) := (isCoseparator_prod _ _).2 <| ObjectProperty.IsCoseparating.of_le hG <| by simp theorem isCoseparator_prod_of_isCoseparator_right (G H : C) [HasBinaryProduct G H] (hH : IsCoseparator H) : IsCoseparator (G ⨯ H) := (isCoseparator_prod _ _).2 <| ObjectProperty.IsCoseparating.of_le hH <| by simp theorem isCoseparator_pi_of_isCoseparator {β : Type w} (f : β → C) [HasProduct f] (b : β) (hb : IsCoseparator (f b)) : IsCoseparator (∏ᶜ f) := (isCoseparator_pi _).2 <| ObjectProperty.IsCoseparating.of_le hb <| by simp end ZeroMorphisms theorem isDetector_iff_reflectsIsomorphisms_coyoneda_obj (G : C) : IsDetector G ↔ (coyoneda.obj (op G)).ReflectsIsomorphisms := by refine ⟨fun hG => ⟨fun f hf => hG.def _ fun h => ?_⟩, fun h => (isDetector_def _).2 fun X Y f hf => ?_⟩ · rw [isIso_iff_bijective, Function.bijective_iff_existsUnique] at hf exact hf h · suffices IsIso ((coyoneda.obj (op G)).map f) by exact @isIso_of_reflects_iso _ _ _ _ _ _ _ (coyoneda.obj (op G)) _ h rwa [isIso_iff_bijective, Function.bijective_iff_existsUnique] theorem isCodetector_iff_reflectsIsomorphisms_yoneda_obj (G : C) : IsCodetector G ↔ (yoneda.obj G).ReflectsIsomorphisms := by refine ⟨fun hG => ⟨fun f hf => ?_⟩, fun h => (isCodetector_def _).2 fun X Y f hf => ?_⟩ · refine (isIso_unop_iff _).1 (hG.def _ ?_) rwa [isIso_iff_bijective, Function.bijective_iff_existsUnique] at hf · rw [← isIso_op_iff] suffices IsIso ((yoneda.obj G).map f.op) by exact @isIso_of_reflects_iso _ _ _ _ _ _ _ (yoneda.obj G) _ h rwa [isIso_iff_bijective, Function.bijective_iff_existsUnique] theorem wellPowered_of_isDetector [HasPullbacks C] (G : C) (hG : IsDetector G) : WellPowered.{v₁} C := wellPowered_of_isDetecting hG theorem wellPowered_of_isSeparator [HasPullbacks C] [Balanced C] (G : C) (hG : IsSeparator G) : WellPowered.{v₁} C := wellPowered_of_isDetecting hG.isDetector section HasGenerator section Definitions variable (C) /-- For a category `C` and an object `G : C`, `G` is a separator of `C` if the functor `C(G, -)` is faithful. While `IsSeparator G : Prop` is the proposition that `G` is a separator of `C`, an `HasSeparator C : Prop` is the proposition that such a separator exists. Note that `HasSeparator C` is a proposition. It does not designate a favored separator and merely asserts the existence of one. -/ class HasSeparator : Prop where hasSeparator : ∃ G : C, IsSeparator G /-- For a category `C` and an object `G : C`, `G` is a coseparator of `C` if the functor `C(-, G)` is faithful. While `IsCoseparator G : Prop` is the proposition that `G` is a coseparator of `C`, an `HasCoseparator C : Prop` is the proposition that such a coseparator exists. Note that `HasCoseparator C` is a proposition. It does not designate a favored coseparator and merely asserts the existence of one. -/ class HasCoseparator : Prop where hasCoseparator : ∃ G : C, IsCoseparator G /-- For a category `C` and an object `G : C`, `G` is a detector of `C` if the functor `C(G, -)` reflects isomorphisms. While `IsDetector G : Prop` is the proposition that `G` is a detector of `C`, an `HasDetector C : Prop` is the proposition that such a detector exists. Note that `HasDetector C` is a proposition. It does not designate a favored detector and merely asserts the existence of one. -/ class HasDetector : Prop where hasDetector : ∃ G : C, IsDetector G /-- For a category `C` and an object `G : C`, `G` is a codetector of `C` if the functor `C(-, G)` reflects isomorphisms. While `IsCodetector G : Prop` is the proposition that `G` is a codetector of `C`, an `HasCodetector C : Prop` is the proposition that such a codetector exists. Note that `HasCodetector C` is a proposition. It does not designate a favored codetector and merely asserts the existence of one. -/ class HasCodetector : Prop where hasCodetector : ∃ G : C, IsCodetector G end Definitions section Choice variable (C) /-- Given a category `C` that has a separator (`HasSeparator C`), `separator C` is an arbitrarily chosen separator of `C`. -/ noncomputable def separator [HasSeparator C] : C := HasSeparator.hasSeparator.choose /-- Given a category `C` that has a coseparator (`HasCoseparator C`), `coseparator C` is an arbitrarily chosen coseparator of `C`. -/ noncomputable def coseparator [HasCoseparator C] : C := HasCoseparator.hasCoseparator.choose /-- Given a category `C` that has a detector (`HasDetector C`), `detector C` is an arbitrarily chosen detector of `C`. -/ noncomputable def detector [HasDetector C] : C := HasDetector.hasDetector.choose /-- Given a category `C` that has a codetector (`HasCodetector C`), `codetector C` is an arbitrarily chosen codetector of `C`. -/ noncomputable def codetector [HasCodetector C] : C := HasCodetector.hasCodetector.choose theorem isSeparator_separator [HasSeparator C] : IsSeparator (separator C) := HasSeparator.hasSeparator.choose_spec theorem isDetector_separator [Balanced C] [HasSeparator C] : IsDetector (separator C) := isSeparator_separator C |>.isDetector theorem isCoseparator_coseparator [HasCoseparator C] : IsCoseparator (coseparator C) := HasCoseparator.hasCoseparator.choose_spec theorem isCodetector_coseparator [Balanced C] [HasCoseparator C] : IsCodetector (coseparator C) := isCoseparator_coseparator C |>.isCodetector theorem isDetector_detector [HasDetector C] : IsDetector (detector C) := HasDetector.hasDetector.choose_spec theorem isSeparator_detector [HasEqualizers C] [HasDetector C] : IsSeparator (detector C) := isDetector_detector C |>.isSeparator theorem isCodetector_codetector [HasCodetector C] : IsCodetector (codetector C) := HasCodetector.hasCodetector.choose_spec theorem isCoseparator_codetector [HasCoequalizers C] [HasCodetector C] : IsCoseparator (codetector C) := isCodetector_codetector C |>.isCoseparator end Choice section Instances theorem HasSeparator.hasDetector [Balanced C] [HasSeparator C] : HasDetector C := ⟨_, isDetector_separator C⟩ theorem HasDetector.hasSeparator [HasEqualizers C] [HasDetector C] : HasSeparator C := ⟨_, isSeparator_detector C⟩ theorem HasCoseparator.hasCodetector [Balanced C] [HasCoseparator C] : HasCodetector C := ⟨_, isCodetector_coseparator C⟩ theorem HasCodetector.hasCoseparator [HasCoequalizers C] [HasCodetector C] : HasCoseparator C := ⟨_, isCoseparator_codetector C⟩ instance HasDetector.wellPowered [HasPullbacks C] [HasDetector C] : WellPowered.{v₁} C := isDetector_detector C |> wellPowered_of_isDetector _ instance HasSeparator.wellPowered [HasPullbacks C] [Balanced C] [HasSeparator C] : WellPowered.{v₁} C := HasSeparator.hasDetector.wellPowered end Instances section Equivalence theorem HasSeparator.of_equivalence [HasSeparator C] (α : C ≌ D) : HasSeparator D := ⟨α.functor.obj (separator C), isSeparator_separator C |>.of_equivalence α⟩ theorem HasCoseparator.of_equivalence [HasCoseparator C] (α : C ≌ D) : HasCoseparator D := ⟨α.functor.obj (coseparator C), isCoseparator_coseparator C |>.of_equivalence α⟩ end Equivalence section Dual @[simp] theorem hasSeparator_op_iff : HasSeparator Cᵒᵖ ↔ HasCoseparator C := ⟨fun ⟨G, hG⟩ => ⟨unop G, (isCoseparator_unop_iff G).mpr hG⟩, fun ⟨G, hG⟩ => ⟨op G, (isSeparator_op_iff G).mpr hG⟩⟩ @[simp] theorem hasCoseparator_op_iff : HasCoseparator Cᵒᵖ ↔ HasSeparator C := ⟨fun ⟨G, hG⟩ => ⟨unop G, (isSeparator_unop_iff G).mpr hG⟩, fun ⟨G, hG⟩ => ⟨op G, (isCoseparator_op_iff G).mpr hG⟩⟩ @[simp] theorem hasDetector_op_iff : HasDetector Cᵒᵖ ↔ HasCodetector C := ⟨fun ⟨G, hG⟩ => ⟨unop G, (isCodetector_unop_iff G).mpr hG⟩, fun ⟨G, hG⟩ => ⟨op G, (isDetector_op_iff G).mpr hG⟩⟩ @[simp] theorem hasCodetector_op_iff : HasCodetector Cᵒᵖ ↔ HasDetector C := ⟨fun ⟨G, hG⟩ => ⟨unop G, (isDetector_unop_iff G).mpr hG⟩, fun ⟨G, hG⟩ => ⟨op G, (isCodetector_op_iff G).mpr hG⟩⟩ instance HasSeparator.hasCoseparator_op [HasSeparator C] : HasCoseparator Cᵒᵖ := by simp [*] theorem HasSeparator.hasCoseparator_of_hasSeparator_op [h : HasSeparator Cᵒᵖ] : HasCoseparator C := by simp_all instance HasCoseparator.hasSeparator_op [HasCoseparator C] : HasSeparator Cᵒᵖ := by simp [*] theorem HasCoseparator.hasSeparator_of_hasCoseparator_op [HasCoseparator Cᵒᵖ] : HasSeparator C := by simp_all instance HasDetector.hasCodetector_op [HasDetector C] : HasCodetector Cᵒᵖ := by simp [*] theorem HasDetector.hasCodetector_of_hasDetector_op [HasDetector Cᵒᵖ] : HasCodetector C := by simp_all instance HasCodetector.hasDetector_op [HasCodetector C] : HasDetector Cᵒᵖ := by simp [*] theorem HasCodetector.hasDetector_of_hasCodetector_op [HasCodetector Cᵒᵖ] : HasDetector C := by simp_all end Dual end HasGenerator @[deprecated (since := "2025-10-06")] alias IsSeparating := ObjectProperty.IsSeparating @[deprecated (since := "2025-10-06")] alias IsCoseparating := ObjectProperty.IsCoseparating @[deprecated (since := "2025-10-06")] alias IsDetecting := ObjectProperty.IsDetecting @[deprecated (since := "2025-10-06")] alias IsCodetecting := ObjectProperty.IsCodetecting @[deprecated (since := "2025-10-06")] alias IsSeparating.of_equivalence := ObjectProperty.IsSeparating.of_equivalence @[deprecated (since := "2025-10-06")] alias IsCoseparating.of_equivalence := ObjectProperty.IsCoseparating.of_equivalence @[deprecated (since := "2025-10-06")] alias isSeparating_op_iff := ObjectProperty.isSeparating_op_iff @[deprecated (since := "2025-10-06")] alias isCoseparating_op_iff := ObjectProperty.isCoseparating_op_iff @[deprecated (since := "2025-10-06")] alias isSeparating_unop_iff := ObjectProperty.isSeparating_op_iff @[deprecated (since := "2025-10-06")] alias isCoseparating_unop_iff := ObjectProperty.isCoseparating_op_iff @[deprecated (since := "2025-10-06")] alias isDetecting_op_iff := ObjectProperty.isDetecting_op_iff @[deprecated (since := "2025-10-06")] alias isCodetecting_op_iff := ObjectProperty.isCodetecting_op_iff @[deprecated (since := "2025-10-06")] alias isDetecting_unop_iff := ObjectProperty.isDetecting_op_iff @[deprecated (since := "2025-10-06")] alias isCodetecting_unop_iff := ObjectProperty.isCodetecting_op_iff @[deprecated (since := "2025-10-06")] alias IsDetecting.isSeparating := ObjectProperty.IsDetecting.isSeparating @[deprecated (since := "2025-10-06")] alias IsCodetecting.isCoseparating := ObjectProperty.IsCodetecting.isCoseparating @[deprecated (since := "2025-10-06")] alias IsSeparating.isDetecting := ObjectProperty.IsSeparating.isDetecting @[deprecated (since := "2025-10-06")] alias IsDetecting.isIso_iff_of_mono := ObjectProperty.IsDetecting.isIso_iff_of_mono @[deprecated (since := "2025-10-06")] alias IsCodetecting.isIso_iff_of_epi := ObjectProperty.IsCodetecting.isIso_iff_of_epi @[deprecated (since := "2025-10-06")] alias IsCoseparating.isCodetecting := ObjectProperty.IsCoseparating.isCodetecting @[deprecated (since := "2025-10-06")] alias isDetecting_iff_isSeparating := ObjectProperty.isDetecting_iff_isSeparating @[deprecated (since := "2025-10-06")] alias isCodetecting_iff_isCoseparating := ObjectProperty.isCodetecting_iff_isCoseparating @[deprecated (since := "2025-10-06")] alias IsSeparating.mono := ObjectProperty.IsSeparating.of_le @[deprecated (since := "2025-10-06")] alias IsCoseparating.mono := ObjectProperty.IsCoseparating.of_le @[deprecated (since := "2025-10-06")] alias IsDetecting.mono := ObjectProperty.IsDetecting.of_le @[deprecated (since := "2025-10-06")] alias IsCodetecting.mono := ObjectProperty.IsCodetecting.of_le @[deprecated (since := "2025-10-06")] alias thin_of_isSeparating_empty := ObjectProperty.isThin_of_isSeparating_bot @[deprecated (since := "2025-10-06")] alias isSeparating_empty_of_thin := ObjectProperty.isSeparating_bot_of_isThin @[deprecated (since := "2025-10-06")] alias thin_of_isCoseparating_empty := ObjectProperty.isThin_of_isCoseparating_bot @[deprecated (since := "2025-10-06")] alias isCoseparating_empty_of_thin := ObjectProperty.isCoseparating_bot_of_isThin @[deprecated (since := "2025-10-06")] alias groupoid_of_isDetecting_empty := ObjectProperty.isGroupoid_of_isDetecting_bot @[deprecated (since := "2025-10-06")] alias isDetecting_empty_of_groupoid := ObjectProperty.isDetecting_bot_of_isGroupoid @[deprecated (since := "2025-10-06")] alias groupoid_of_isCodetecting_empty := ObjectProperty.isGroupoid_of_isCodetecting_bot @[deprecated (since := "2025-10-06")] alias isCodetecting_empty_of_groupoid := ObjectProperty.isCodetecting_bot_of_isGroupoid @[deprecated (since := "2025-10-07")] alias isSeparating_iff_epi := ObjectProperty.isSeparating_iff_epi @[deprecated (since := "2025-10-07")] alias isCoseparating_iff_mono := ObjectProperty.isCoseparating_iff_mono @[deprecated (since := "2025-10-07")] alias IsSeparating.isSeparator_coproduct := ObjectProperty.IsSeparating.isSeparator_coproduct @[deprecated (since := "2025-10-07")] alias StructuredArrow.isCoseparating_proj_preimage := StructuredArrow.isCoseparating_inverseImage_proj @[deprecated (since := "2025-10-07")] alias CostructuredArrow.isSeparating_proj_preimage := CostructuredArrow.isSeparating_inverseImage_proj end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Generator/Sheaf.lean
import Mathlib.CategoryTheory.Generator.Presheaf import Mathlib.CategoryTheory.Sites.Sheafification import Mathlib.CategoryTheory.Sites.Limits /-! # Generators in the category of sheaves In this file, we show that if `J : GrothendieckTopology C` and `A` is a preadditive category which has a separator (and suitable coproducts), then `Sheaf J A` has a separator. -/ universe w v' v u' u namespace CategoryTheory open Limits Opposite namespace Sheaf variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) {A : Type u'} [Category.{v'} A] [HasCoproducts.{v} A] [HasWeakSheafify J A] /-- Given `J : GrothendieckTopology C`, `X : C` and `M : A`, this is the associated sheaf to the presheaf `Presheaf.freeYoneda X M`. -/ noncomputable def freeYoneda (X : C) (M : A) : Sheaf J A := (presheafToSheaf J A).obj (Presheaf.freeYoneda X M) variable {J} in /-- The bijection `(Sheaf.freeYoneda J X M ⟶ F) ≃ (M ⟶ F.val.obj (op X))` when `F : Sheaf J A`, `X : C` and `M : A`. -/ noncomputable def freeYonedaHomEquiv {X : C} {M : A} {F : Sheaf J A} : (freeYoneda J X M ⟶ F) ≃ (M ⟶ F.val.obj (op X)) := ((sheafificationAdjunction J A).homEquiv _ _).trans Presheaf.freeYonedaHomEquiv lemma isSeparating {ι : Type w} {S : ι → A} (hS : ObjectProperty.IsSeparating (.ofObj S)) : ObjectProperty.IsSeparating (.ofObj (fun (⟨X, i⟩ : C × ι) ↦ freeYoneda J X (S i))) := by intro F G f g hfg refine (sheafToPresheaf J A).map_injective (Presheaf.isSeparating C hS _ _ ?_) rintro _ ⟨X, i⟩ a apply ((sheafificationAdjunction _ _).homEquiv _ _).symm.injective simpa only [← Adjunction.homEquiv_naturality_right_symm] using hfg _ (ObjectProperty.ofObj_apply _ ⟨X, i⟩) (((sheafificationAdjunction _ _).homEquiv _ _).symm a) lemma isSeparator {ι : Type w} {S : ι → A} (hS : ObjectProperty.IsSeparating (.ofObj S)) [HasCoproduct (fun (⟨X, i⟩ : C × ι) ↦ freeYoneda J X (S i))] [Preadditive A] : IsSeparator (∐ (fun (⟨X, i⟩ : C × ι) ↦ freeYoneda J X (S i))) := (isSeparating J hS).isSeparator_coproduct variable (A) in instance hasSeparator [HasSeparator A] [Preadditive A] [HasCoproducts.{u} A] : HasSeparator (Sheaf J A) where hasSeparator := ⟨_, isSeparator J (S := fun (_ : Unit) ↦ separator A) (by simpa using isSeparator_separator A)⟩ end Sheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Finite.lean
import Mathlib.CategoryTheory.Sites.Pretopology import Mathlib.Data.Set.Finite.Lattice /-! # The Finite Pretopology In this file we define the finite pretopology on a category, which consists of presieves that contain only finitely many arrows. ## Main Definitions - `CategoryTheory.Precoverage.finite`: The finite precoverage on a category. - `CategoryTheory.Pretopology.finite`: The finite pretopology on a category. -/ universe v v₁ u u₁ namespace CategoryTheory open Presieve namespace Precoverage /-- The finite precoverage on a category consists of finite presieves, i.e. a presieve with finitely many maps after uncurrying. -/ def finite (C : Type u) [Category.{v} C] : Precoverage C where coverings X := { s : Presieve X | s.uncurry.Finite } variable {C : Type u} [Category.{v} C] @[simp] lemma mem_finite_iff {X : C} {s : Presieve X} : s ∈ finite C X ↔ s.uncurry.Finite := Iff.rfl theorem ofArrows_mem_finite {X : C} {ι : Type*} [Finite ι] (Y : ι → C) (f : (i : ι) → Y i ⟶ X) : ofArrows Y f ∈ finite C X := by simpa using Set.finite_range _ instance : (finite C).HasIsos where mem_coverings_of_isIso := by simp end Precoverage namespace Pretopology open Limits /-- The finite pretopology on a category consists of finite presieves, i.e. a presieve with finitely many maps after uncurrying. -/ @[simps toPrecoverage] def finite (C : Type u) [Category.{v} C] [HasPullbacks C] : Pretopology C where __ := Precoverage.finite C has_isos _ _ _ := Precoverage.mem_coverings_of_isIso _ pullbacks X Y u s hs := by simpa using hs.image _ transitive X s t hs ht := by simpa using hs.biUnion' fun _ _ ↦ (ht _ _).image _ variable {C : Type u} [Category.{v} C] [HasPullbacks C] theorem ofArrows_mem_finite {X : C} {ι : Type*} [Finite ι] (Y : ι → C) (f : (i : ι) → Y i ⟶ X) : ofArrows Y f ∈ (finite C).coverings X := Precoverage.ofArrows_mem_finite _ _ end Pretopology end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/LocallyFullyFaithful.lean
import Mathlib.CategoryTheory.Sites.LocallySurjective /-! # Locally fully faithful functors into sites ## Main results - `CategoryTheory.Functor.IsLocallyFull`: A functor `G : C ⥤ D` is locally full w.r.t. a topology on `D` if for every `f : G.obj U ⟶ G.obj V`, the set of `G.map fᵢ : G.obj Wᵢ ⟶ G.obj U` such that `G.map fᵢ ≫ f` is in the image of `G` is a coverage of the topology on `D`. - `CategoryTheory.Functor.IsLocallyFaithful`: A functor `G : C ⥤ D` is locally faithful w.r.t. a topology on `D` if for every `f₁ f₂ : U ⟶ V` whose images in `D` are equal, the set of `G.map gᵢ : G.obj Wᵢ ⟶ G.obj U` such that `gᵢ ≫ f₁ = gᵢ ≫ f₂` is a coverage of the topology on `D`. ## References * [caramello2020]: Olivia Caramello, *Denseness conditions, morphisms and equivalences of toposes* -/ universe w vC vD uC uD namespace CategoryTheory variable {C : Type uC} [Category.{vC} C] {D : Type uD} [Category.{vD} D] (G : C ⥤ D) variable (J : GrothendieckTopology C) (K : GrothendieckTopology D) /-- For a functor `G : C ⥤ D`, and a morphism `f : G.obj U ⟶ G.obj V`, `Functor.imageSieve G f` is the sieve of `U` consisting of those arrows whose composition with `f` has a lift in `G`. This is the image sieve of `f` under `yonedaMap G V` and hence the name. See `Functor.imageSieve_eq_imageSieve`. -/ def Functor.imageSieve {U V : C} (f : G.obj U ⟶ G.obj V) : Sieve U where arrows _ i := ∃ l, G.map l = G.map i ≫ f downward_closed := by rintro Y₁ Y₂ i₁ ⟨l, hl⟩ i₂ exact ⟨i₂ ≫ l, by simp [hl]⟩ @[simp] lemma Functor.imageSieve_map {U V : C} (f : U ⟶ V) : G.imageSieve (G.map f) = ⊤ := by ext W g; simpa using ⟨g ≫ f, by simp⟩ /-- For two arrows `f₁ f₂ : U ⟶ V`, the arrows `i` such that `i ≫ f₁ = i ≫ f₂` forms a sieve. -/ @[simps] def Sieve.equalizer {U V : C} (f₁ f₂ : U ⟶ V) : Sieve U where arrows _ i := i ≫ f₁ = i ≫ f₂ downward_closed := by aesop @[simp] lemma Sieve.equalizer_self {U V : C} (f : U ⟶ V) : equalizer f f = ⊤ := by ext; simp attribute [local instance] Types.instFunLike Types.instConcreteCategory in lemma Sieve.equalizer_eq_equalizerSieve {U V : C} (f₁ f₂ : U ⟶ V) : Sieve.equalizer f₁ f₂ = Presheaf.equalizerSieve (F := yoneda.obj _) f₁ f₂ := rfl attribute [local instance] Types.instFunLike Types.instConcreteCategory in lemma Functor.imageSieve_eq_imageSieve {D : Type uD} [Category.{vC} D] (G : C ⥤ D) {U V : C} (f : G.obj U ⟶ G.obj V) : G.imageSieve f = Presheaf.imageSieve (yonedaMap G V) f := rfl open Presieve Opposite namespace Functor /-- A functor `G : C ⥤ D` is locally full w.r.t. a topology on `D` if for every `f : G.obj U ⟶ G.obj V`, the set of `G.map fᵢ : G.obj Wᵢ ⟶ G.obj U` such that `G.map fᵢ ≫ f` is in the image of `G` is a coverage of the topology on `D`. -/ class IsLocallyFull : Prop where functorPushforward_imageSieve_mem : ∀ {U V} (f : G.obj U ⟶ G.obj V), (G.imageSieve f).functorPushforward G ∈ K _ /-- A functor `G : C ⥤ D` is locally faithful w.r.t. a topology on `D` if for every `f₁ f₂ : U ⟶ V` whose images in `D` are equal, the set of `G.map gᵢ : G.obj Wᵢ ⟶ G.obj U` such that `gᵢ ≫ f₁ = gᵢ ≫ f₂` is a coverage of the topology on `D`. -/ class IsLocallyFaithful : Prop where functorPushforward_equalizer_mem : ∀ {U V : C} (f₁ f₂ : U ⟶ V), G.map f₁ = G.map f₂ → (Sieve.equalizer f₁ f₂).functorPushforward G ∈ K _ lemma functorPushforward_imageSieve_mem [G.IsLocallyFull K] {U V} (f : G.obj U ⟶ G.obj V) : (G.imageSieve f).functorPushforward G ∈ K _ := Functor.IsLocallyFull.functorPushforward_imageSieve_mem _ lemma functorPushforward_equalizer_mem [G.IsLocallyFaithful K] {U V} (f₁ f₂ : U ⟶ V) (e : G.map f₁ = G.map f₂) : (Sieve.equalizer f₁ f₂).functorPushforward G ∈ K _ := Functor.IsLocallyFaithful.functorPushforward_equalizer_mem _ _ e variable {K} variable {A : Type*} [Category A] (G : C ⥤ D) theorem IsLocallyFull.ext [G.IsLocallyFull K] (ℱ : Sheaf K (Type _)) {X Y : C} (i : G.obj X ⟶ G.obj Y) {s t : ℱ.val.obj (op (G.obj X))} (h : ∀ ⦃Z : C⦄ (j : Z ⟶ X) (f : Z ⟶ Y), G.map f = G.map j ≫ i → ℱ.1.map (G.map j).op s = ℱ.1.map (G.map j).op t) : s = t := by apply (((isSheaf_iff_isSheaf_of_type _ _).1 ℱ.cond) _ (G.functorPushforward_imageSieve_mem K i)).isSeparatedFor.ext rintro Z _ ⟨W, iWX, iZW, ⟨iWY, e⟩, rfl⟩ simp [h iWX iWY e] theorem IsLocallyFaithful.ext [G.IsLocallyFaithful K] (ℱ : Sheaf K (Type _)) {X Y : C} (i₁ i₂ : X ⟶ Y) (e : G.map i₁ = G.map i₂) {s t : ℱ.val.obj (op (G.obj X))} (h : ∀ ⦃Z : C⦄ (j : Z ⟶ X), j ≫ i₁ = j ≫ i₂ → ℱ.1.map (G.map j).op s = ℱ.1.map (G.map j).op t) : s = t := by apply (((isSheaf_iff_isSheaf_of_type _ _).1 ℱ.cond) _ (G.functorPushforward_equalizer_mem K i₁ i₂ e)).isSeparatedFor.ext rintro Z _ ⟨W, iWX, iZW, hiWX, rfl⟩ simp [h iWX hiWX] instance (priority := 900) IsLocallyFull.of_full [G.Full] : G.IsLocallyFull K where functorPushforward_imageSieve_mem f := by rw [← G.map_preimage f] simp only [Functor.imageSieve_map, Sieve.functorPushforward_top, GrothendieckTopology.top_mem] instance (priority := 900) IsLocallyFaithful.of_faithful [G.Faithful] : G.IsLocallyFaithful K where functorPushforward_equalizer_mem f₁ f₂ e := by obtain rfl := G.map_injective e; simp end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/CartesianMonoidal.lean
import Mathlib.CategoryTheory.Monoidal.Cartesian.FunctorCategory import Mathlib.CategoryTheory.Sites.Limits /-! # Chosen finite products on sheaves In this file, we put a `CartesianMonoidalCategory` instance on `A`-valued sheaves for a `GrothendieckTopology` whenever `A` has a `CartesianMonoidalCategory` instance. -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory open Opposite Category Limits Sieve MonoidalCategory CartesianMonoidalCategory variable {C : Type u₁} [Category.{v₁} C] variable {A : Type u₂} [Category.{v₂} A] variable (J : GrothendieckTopology C) variable [CartesianMonoidalCategory A] namespace Sheaf variable (X Y : Sheaf J A) lemma tensorProd_isSheaf : Presheaf.IsSheaf J (X.val ⊗ Y.val) := by apply isSheaf_of_isLimit (E := (Cones.postcompose (pairComp X Y (sheafToPresheaf J A)).inv).obj (BinaryFan.mk (fst X.val Y.val) (snd _ _))) exact (IsLimit.postcomposeInvEquiv _ _).invFun (tensorProductIsBinaryProduct X.val Y.val) lemma tensorUnit_isSheaf : Presheaf.IsSheaf J (𝟙_ (Cᵒᵖ ⥤ A)) := by apply isSheaf_of_isLimit (E := (Cones.postcompose (Functor.uniqueFromEmpty _).inv).obj (asEmptyCone (𝟙_ _))) · exact (IsLimit.postcomposeInvEquiv _ _).invFun isTerminalTensorUnit · exact .empty _ /-- Any `CartesianMonoidalCategory` on `A` induce a `CartesianMonoidalCategory` structure on `A`-valued sheaves. -/ noncomputable instance cartesianMonoidalCategory : CartesianMonoidalCategory (Sheaf J A) := .ofChosenFiniteProducts ({cone := asEmptyCone { val := 𝟙_ (Cᵒᵖ ⥤ A), cond := tensorUnit_isSheaf _} isLimit.lift f := ⟨toUnit f.pt.val⟩ isLimit.fac := by rintro _ ⟨⟨⟩⟩ isLimit.uniq x f h := Sheaf.hom_ext _ _ (toUnit_unique f.val _) }) fun X Y ↦ { cone := BinaryFan.mk (P := { val := X.val ⊗ Y.val cond := tensorProd_isSheaf J X Y}) ⟨(fst _ _)⟩ ⟨(snd _ _)⟩ isLimit.lift f := ⟨lift (BinaryFan.fst f).val (BinaryFan.snd f).val⟩ isLimit.fac := by rintro s ⟨⟨j⟩⟩ <;> apply Sheaf.hom_ext <;> simp isLimit.uniq x f h := by apply Sheaf.hom_ext apply CartesianMonoidalCategory.hom_ext · specialize h ⟨.left⟩ rw [Sheaf.hom_ext_iff] at h simpa using h · specialize h ⟨.right⟩ rw [Sheaf.hom_ext_iff] at h simpa using h } @[simp] lemma cartesianMonoidalCategoryFst_val : (fst X Y).val = fst X.val Y.val := rfl @[simp] lemma cartesianMonoidalCategorySnd_val : (snd X Y).val = snd X.val Y.val := rfl variable {X Y} variable {W : Sheaf J A} (f : W ⟶ X) (g : W ⟶ Y) @[simp] lemma cartesianMonoidalCategoryLift_val : (lift f g).val = lift f.val g.val := rfl @[simp] lemma cartesianMonoidalCategoryWhiskerLeft_val : (X ◁ f).val = X.val ◁ f.val := rfl @[simp] lemma cartesianMonoidalCategoryWhiskerRight_val : (f ▷ X).val = f.val ▷ X.val := rfl end Sheaf /-- The inclusion from sheaves to presheaves is monoidal with respect to the Cartesian monoidal structures. -/ noncomputable instance sheafToPresheafMonoidal : (sheafToPresheaf J A).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := .refl _ μIso F G := .refl _ } open Functor.LaxMonoidal Functor.OplaxMonoidal @[simp] lemma sheafToPresheaf_ε : ε (sheafToPresheaf J A) = 𝟙 _ := rfl @[simp] lemma sheafToPresheaf_η : η (sheafToPresheaf J A) = 𝟙 _ := rfl variable {J} @[simp] lemma sheafToPresheaf_μ (X Y : Sheaf J A) : μ (sheafToPresheaf J A) X Y = 𝟙 _ := rfl @[simp] lemma sheafToPresheaf_δ (X Y : Sheaf J A) : δ (sheafToPresheaf J A) X Y = 𝟙 _ := rfl end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/LocallySurjective.lean
import Mathlib.CategoryTheory.Sites.Subsheaf import Mathlib.CategoryTheory.Sites.CompatibleSheafification import Mathlib.CategoryTheory.Sites.LocallyInjective /-! # Locally surjective morphisms ## Main definitions - `IsLocallySurjective` : A morphism of presheaves valued in a concrete category is locally surjective with respect to a Grothendieck topology if every section in the target is locally in the set-theoretic image, i.e. the image sheaf coincides with the target. ## Main results - `Presheaf.isLocallySurjective_toSheafify`: `toSheafify` is locally surjective. - `Sheaf.isLocallySurjective_iff_epi`: a morphism of sheaves of types is locally surjective iff it is epi -/ universe v u w v' u' w' open Opposite CategoryTheory CategoryTheory.GrothendieckTopology CategoryTheory.Functor namespace CategoryTheory variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) variable {A : Type u'} [Category.{v'} A] {FA : A → A → Type*} {CA : A → Type w'} variable [∀ X Y, FunLike (FA X Y) (CA X) (CA Y)] [ConcreteCategory.{w'} A FA] namespace Presheaf /-- Given `f : F ⟶ G`, a morphism between presieves, and `s : G.obj (op U)`, this is the sieve of `U` consisting of the `i : V ⟶ U` such that `s` restricted along `i` is in the image of `f`. -/ @[simps -isSimp] def imageSieve {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) {U : C} (s : ToType (G.obj (op U))) : Sieve U where arrows V i := ∃ t : ToType (F.obj (op V)), f.app _ t = G.map i.op s downward_closed := by rintro V W i ⟨t, ht⟩ j refine ⟨F.map j.op t, ?_⟩ rw [op_comp, G.map_comp, ConcreteCategory.comp_apply, ← ht, NatTrans.naturality_apply f] theorem imageSieve_eq_sieveOfSection {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) {U : C} (s : ToType (G.obj (op U))) : imageSieve f s = (Subpresheaf.range (whiskerRight f (forget A))).sieveOfSection s := rfl attribute [local instance] Types.instFunLike Types.instConcreteCategory in theorem imageSieve_whisker_forget {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) {U : C} (s : ToType (G.obj (op U))) : imageSieve (whiskerRight f (forget A)) s = imageSieve f s := rfl theorem imageSieve_app {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) {U : C} (s : ToType (F.obj (op U))) : imageSieve f (f.app _ s) = ⊤ := by ext V i simp only [Sieve.top_apply, iff_true, imageSieve_apply] exact ⟨F.map i.op s, NatTrans.naturality_apply f i.op s⟩ /-- If a morphism `g : V ⟶ U.unop` belongs to the sieve `imageSieve f s g`, then this is choice of a preimage of `G.map g.op s` in `F.obj (op V)`, see `app_localPreimage`. -/ noncomputable def localPreimage {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) {U : Cᵒᵖ} (s : ToType (G.obj U)) {V : C} (g : V ⟶ U.unop) (hg : imageSieve f s g) : ToType (F.obj (op V)) := hg.choose @[simp] lemma app_localPreimage {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) {U : Cᵒᵖ} (s : ToType (G.obj U)) {V : C} (g : V ⟶ U.unop) (hg : imageSieve f s g) : f.app _ (localPreimage f s g hg) = G.map g.op s := hg.choose_spec /-- A morphism of presheaves `f : F ⟶ G` is locally surjective with respect to a Grothendieck topology if every section of `G` is locally in the image of `f`. -/ class IsLocallySurjective {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) : Prop where imageSieve_mem {U : C} (s : ToType (G.obj (op U))) : imageSieve f s ∈ J U lemma imageSieve_mem {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) [IsLocallySurjective J f] {U : Cᵒᵖ} (s : ToType (G.obj U)) : imageSieve f s ∈ J U.unop := IsLocallySurjective.imageSieve_mem _ attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) [IsLocallySurjective J f] : IsLocallySurjective J (whiskerRight f (forget A)) where imageSieve_mem s := imageSieve_mem J f s theorem isLocallySurjective_iff_range_sheafify_eq_top {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) : IsLocallySurjective J f ↔ (Subpresheaf.range (whiskerRight f (forget A))).sheafify J = ⊤ := by simp only [Subpresheaf.ext_iff, funext_iff, Set.ext_iff, Subpresheaf.top_obj, Set.top_eq_univ, Set.mem_univ, iff_true] exact ⟨fun H _ => H.imageSieve_mem, fun H => ⟨H _⟩⟩ attribute [local instance] Types.instFunLike Types.instConcreteCategory in theorem isLocallySurjective_iff_range_sheafify_eq_top' {F G : Cᵒᵖ ⥤ Type w} (f : F ⟶ G) : IsLocallySurjective J f ↔ (Subpresheaf.range f).sheafify J = ⊤ := by apply isLocallySurjective_iff_range_sheafify_eq_top attribute [local instance] Types.instFunLike Types.instConcreteCategory in theorem isLocallySurjective_iff_whisker_forget {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) : IsLocallySurjective J f ↔ IsLocallySurjective J (whiskerRight f (forget A)) := by simp only [isLocallySurjective_iff_range_sheafify_eq_top] rfl theorem isLocallySurjective_of_surjective {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) (H : ∀ U, Function.Surjective (f.app U)) : IsLocallySurjective J f where imageSieve_mem {U} s := by obtain ⟨t, rfl⟩ := H _ s rw [imageSieve_app] exact J.top_mem _ instance isLocallySurjective_of_iso {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) [IsIso f] : IsLocallySurjective J f := by apply isLocallySurjective_of_surjective intro U apply Function.Bijective.surjective rw [← isIso_iff_bijective, ← ConcreteCategory.forget_map_eq_coe] infer_instance instance isLocallySurjective_comp {F₁ F₂ F₃ : Cᵒᵖ ⥤ A} (f₁ : F₁ ⟶ F₂) (f₂ : F₂ ⟶ F₃) [IsLocallySurjective J f₁] [IsLocallySurjective J f₂] : IsLocallySurjective J (f₁ ≫ f₂) where imageSieve_mem s := by have : (Sieve.bind (imageSieve f₂ s) fun _ _ h => imageSieve f₁ h.choose) ≤ imageSieve (f₁ ≫ f₂) s := by rintro V i ⟨W, i, j, H, ⟨t', ht'⟩, rfl⟩ refine ⟨t', ?_⟩ rw [op_comp, F₃.map_comp, NatTrans.comp_app, ConcreteCategory.comp_apply, ConcreteCategory.comp_apply, ht', NatTrans.naturality_apply, H.choose_spec] apply J.superset_covering this apply J.bind_covering · apply imageSieve_mem · intros; apply imageSieve_mem lemma isLocallySurjective_of_isLocallySurjective {F₁ F₂ F₃ : Cᵒᵖ ⥤ A} (f₁ : F₁ ⟶ F₂) (f₂ : F₂ ⟶ F₃) [IsLocallySurjective J (f₁ ≫ f₂)] : IsLocallySurjective J f₂ where imageSieve_mem {X} x := by refine J.superset_covering ?_ (imageSieve_mem J (f₁ ≫ f₂) x) intro Y g hg exact ⟨f₁.app _ (localPreimage (f₁ ≫ f₂) x g hg), by simpa using app_localPreimage (f₁ ≫ f₂) x g hg⟩ lemma isLocallySurjective_of_isLocallySurjective_fac {F₁ F₂ F₃ : Cᵒᵖ ⥤ A} {f₁ : F₁ ⟶ F₂} {f₂ : F₂ ⟶ F₃} {f₃ : F₁ ⟶ F₃} (fac : f₁ ≫ f₂ = f₃) [IsLocallySurjective J f₃] : IsLocallySurjective J f₂ := by subst fac exact isLocallySurjective_of_isLocallySurjective J f₁ f₂ lemma isLocallySurjective_iff_of_fac {F₁ F₂ F₃ : Cᵒᵖ ⥤ A} {f₁ : F₁ ⟶ F₂} {f₂ : F₂ ⟶ F₃} {f₃ : F₁ ⟶ F₃} (fac : f₁ ≫ f₂ = f₃) [IsLocallySurjective J f₁] : IsLocallySurjective J f₃ ↔ IsLocallySurjective J f₂ := by constructor · intro exact isLocallySurjective_of_isLocallySurjective_fac J fac · intro rw [← fac] infer_instance lemma comp_isLocallySurjective_iff {F₁ F₂ F₃ : Cᵒᵖ ⥤ A} (f₁ : F₁ ⟶ F₂) (f₂ : F₂ ⟶ F₃) [IsLocallySurjective J f₁] : IsLocallySurjective J (f₁ ≫ f₂) ↔ IsLocallySurjective J f₂ := isLocallySurjective_iff_of_fac J rfl variable {J} in lemma isLocallySurjective_of_le {K : GrothendieckTopology C} (hJK : J ≤ K) {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) (h : IsLocallySurjective J f) : IsLocallySurjective K f where imageSieve_mem s := by apply hJK; exact h.1 _ lemma isLocallyInjective_of_isLocallyInjective_of_isLocallySurjective {F₁ F₂ F₃ : Cᵒᵖ ⥤ A} (f₁ : F₁ ⟶ F₂) (f₂ : F₂ ⟶ F₃) [IsLocallyInjective J (f₁ ≫ f₂)] [IsLocallySurjective J f₁] : IsLocallyInjective J f₂ where equalizerSieve_mem {X} x₁ x₂ h := by let S := imageSieve f₁ x₁ ⊓ imageSieve f₁ x₂ have hS : S ∈ J X.unop := by apply J.intersection_covering all_goals apply imageSieve_mem let T : ∀ ⦃Y : C⦄ (f : Y ⟶ X.unop) (_ : S f), Sieve Y := fun Y f hf => equalizerSieve (localPreimage f₁ x₁ f hf.1) (localPreimage f₁ x₂ f hf.2) refine J.superset_covering ?_ (J.transitive hS (Sieve.bind S.1 T) ?_) · rintro Y f ⟨Z, a, g, hg, ha, rfl⟩ simpa using congr_arg (f₁.app _) ha · intro Y f hf apply J.superset_covering (Sieve.le_pullback_bind _ _ _ hf) apply equalizerSieve_mem J (f₁ ≫ f₂) dsimp rw [ConcreteCategory.comp_apply, ConcreteCategory.comp_apply, app_localPreimage, app_localPreimage, NatTrans.naturality_apply, NatTrans.naturality_apply, h] lemma isLocallyInjective_of_isLocallyInjective_of_isLocallySurjective_fac {F₁ F₂ F₃ : Cᵒᵖ ⥤ A} {f₁ : F₁ ⟶ F₂} {f₂ : F₂ ⟶ F₃} (f₃ : F₁ ⟶ F₃) (fac : f₁ ≫ f₂ = f₃) [IsLocallyInjective J f₃] [IsLocallySurjective J f₁] : IsLocallyInjective J f₂ := by subst fac exact isLocallyInjective_of_isLocallyInjective_of_isLocallySurjective J f₁ f₂ lemma isLocallySurjective_of_isLocallySurjective_of_isLocallyInjective {F₁ F₂ F₃ : Cᵒᵖ ⥤ A} (f₁ : F₁ ⟶ F₂) (f₂ : F₂ ⟶ F₃) [IsLocallySurjective J (f₁ ≫ f₂)] [IsLocallyInjective J f₂] : IsLocallySurjective J f₁ where imageSieve_mem {X} x := by let S := imageSieve (f₁ ≫ f₂) (f₂.app _ x) let T : ∀ ⦃Y : C⦄ (f : Y ⟶ X) (_ : S f), Sieve Y := fun Y f hf => equalizerSieve (f₁.app _ (localPreimage (f₁ ≫ f₂) (f₂.app _ x) f hf)) (F₂.map f.op x) refine J.superset_covering ?_ (J.transitive (imageSieve_mem J (f₁ ≫ f₂) (f₂.app _ x)) (Sieve.bind S.1 T) ?_) · rintro Y _ ⟨Z, a, g, hg, ha, rfl⟩ exact ⟨F₁.map a.op (localPreimage (f₁ ≫ f₂) _ _ hg), by simpa using ha⟩ · intro Y f hf apply J.superset_covering (Sieve.le_pullback_bind _ _ _ hf) apply equalizerSieve_mem J f₂ rw [NatTrans.naturality_apply, ← app_localPreimage (f₁ ≫ f₂) _ _ hf, NatTrans.comp_app, ConcreteCategory.comp_apply] lemma isLocallySurjective_of_isLocallySurjective_of_isLocallyInjective_fac {F₁ F₂ F₃ : Cᵒᵖ ⥤ A} {f₁ : F₁ ⟶ F₂} {f₂ : F₂ ⟶ F₃} (f₃ : F₁ ⟶ F₃) (fac : f₁ ≫ f₂ = f₃) [IsLocallySurjective J f₃] [IsLocallyInjective J f₂] : IsLocallySurjective J f₁ := by subst fac exact isLocallySurjective_of_isLocallySurjective_of_isLocallyInjective J f₁ f₂ lemma comp_isLocallyInjective_iff {F₁ F₂ F₃ : Cᵒᵖ ⥤ A} (f₁ : F₁ ⟶ F₂) (f₂ : F₂ ⟶ F₃) [IsLocallyInjective J f₁] [IsLocallySurjective J f₁] : IsLocallyInjective J (f₁ ≫ f₂) ↔ IsLocallyInjective J f₂ := by constructor · intro exact isLocallyInjective_of_isLocallyInjective_of_isLocallySurjective J f₁ f₂ · intro infer_instance lemma isLocallySurjective_comp_iff {F₁ F₂ F₃ : Cᵒᵖ ⥤ A} (f₁ : F₁ ⟶ F₂) (f₂ : F₂ ⟶ F₃) [IsLocallyInjective J f₂] [IsLocallySurjective J f₂] : IsLocallySurjective J (f₁ ≫ f₂) ↔ IsLocallySurjective J f₁ := by constructor · intro exact isLocallySurjective_of_isLocallySurjective_of_isLocallyInjective J f₁ f₂ · intro infer_instance attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance {F₁ F₂ : Cᵒᵖ ⥤ Type w} (f : F₁ ⟶ F₂) : IsLocallySurjective J (Subpresheaf.toRangeSheafify J f) where imageSieve_mem {X} := by rintro ⟨s, hs⟩ refine J.superset_covering ?_ hs rintro Y g ⟨t, ht⟩ exact ⟨t, Subtype.ext ht⟩ attribute [local instance] Types.instFunLike Types.instConcreteCategory in /-- The image of `F` in `J.sheafify F` is isomorphic to the sheafification. -/ noncomputable def sheafificationIsoImagePresheaf (F : Cᵒᵖ ⥤ Type max u v) : J.sheafify F ≅ ((Subpresheaf.range (J.toSheafify F)).sheafify J).toPresheaf where hom := J.sheafifyLift (Subpresheaf.toRangeSheafify J _) ((isSheaf_iff_isSheaf_of_type J _).mpr <| Subpresheaf.sheafify_isSheaf _ <| (isSheaf_iff_isSheaf_of_type J _).mp <| GrothendieckTopology.sheafify_isSheaf J _) inv := Subpresheaf.ι _ hom_inv_id := J.sheafify_hom_ext _ _ (J.sheafify_isSheaf _) (by simp [Subpresheaf.toRangeSheafify]) inv_hom_id := by rw [← cancel_mono (Subpresheaf.ι _), Category.id_comp, Category.assoc] refine Eq.trans ?_ (Category.comp_id _) congr 1 exact J.sheafify_hom_ext _ _ (J.sheafify_isSheaf _) (by simp [Subpresheaf.toRangeSheafify]) section open GrothendieckTopology.Plus attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance isLocallySurjective_toPlus (P : Cᵒᵖ ⥤ Type max u v) : IsLocallySurjective J (J.toPlus P) where imageSieve_mem x := by obtain ⟨S, x, rfl⟩ := exists_rep x refine J.superset_covering (fun Y f hf => ⟨x.1 ⟨Y, f, hf⟩, ?_⟩) S.2 dsimp rw [toPlus_eq_mk, res_mk_eq_mk_pullback, eq_mk_iff_exists] refine ⟨S.pullback f, homOfLE le_top, 𝟙 _, ?_⟩ ext ⟨Z, g, hg⟩ simpa using x.2 { fst.hf := hf, snd.hf := S.1.downward_closed hf g, r.g₁ := g, r.g₂ := 𝟙 Z, .. } attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance isLocallySurjective_toSheafify (P : Cᵒᵖ ⥤ Type max u v) : IsLocallySurjective J (J.toSheafify P) := by dsimp [GrothendieckTopology.toSheafify] rw [GrothendieckTopology.plusMap_toPlus] infer_instance attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance isLocallySurjective_toSheafify' {D : Type*} [Category D] {FD : D → D → Type*} {CD : D → Type (max u v)} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{max u v} D FD] (P : Cᵒᵖ ⥤ D) [HasWeakSheafify J D] [J.HasSheafCompose (forget D)] [J.PreservesSheafification (forget D)] : IsLocallySurjective J (toSheafify J P) := by rw [isLocallySurjective_iff_whisker_forget, ← sheafComposeIso_hom_fac, ← toSheafify_plusPlusIsoSheafify_hom] infer_instance end end Presheaf namespace Sheaf variable {J} variable {F₁ F₂ F₃ : Sheaf J A} (φ : F₁ ⟶ F₂) (ψ : F₂ ⟶ F₃) /-- If `φ : F₁ ⟶ F₂` is a morphism of sheaves, this is an abbreviation for `Presheaf.IsLocallySurjective J φ.val`. -/ abbrev IsLocallySurjective := Presheaf.IsLocallySurjective J φ.val lemma isLocallySurjective_sheafToPresheaf_map_iff : Presheaf.IsLocallySurjective J ((sheafToPresheaf J A).map φ) ↔ IsLocallySurjective φ := by rfl instance isLocallySurjective_comp [IsLocallySurjective φ] [IsLocallySurjective ψ] : IsLocallySurjective (φ ≫ ψ) := Presheaf.isLocallySurjective_comp J φ.val ψ.val instance isLocallySurjective_of_iso [IsIso φ] : IsLocallySurjective φ := by have : IsIso φ.val := (inferInstance : IsIso ((sheafToPresheaf J A).map φ)) infer_instance attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance {F G : Sheaf J (Type w)} (f : F ⟶ G) : IsLocallySurjective (Sheaf.toImage f) := by dsimp [Sheaf.toImage] infer_instance variable [J.HasSheafCompose (forget A)] attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance [IsLocallySurjective φ] : IsLocallySurjective ((sheafCompose J (forget A)).map φ) := (Presheaf.isLocallySurjective_iff_whisker_forget J φ.val).1 inferInstance attribute [local instance] Types.instFunLike Types.instConcreteCategory in theorem isLocallySurjective_iff_isIso {F G : Sheaf J (Type w)} (f : F ⟶ G) : IsLocallySurjective f ↔ IsIso (Sheaf.imageι f) := by dsimp only [IsLocallySurjective] rw [Sheaf.imageι, Presheaf.isLocallySurjective_iff_range_sheafify_eq_top', Subpresheaf.eq_top_iff_isIso] exact isIso_iff_of_reflects_iso (f := Sheaf.imageι f) (F := sheafToPresheaf J (Type w)) attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance epi_of_isLocallySurjective' {F₁ F₂ : Sheaf J (Type w)} (φ : F₁ ⟶ F₂) [IsLocallySurjective φ] : Epi φ where left_cancellation {Z} f₁ f₂ h := by ext X x apply (((isSheaf_iff_isSheaf_of_type _ _).1 Z.2).isSeparated _ (Presheaf.imageSieve_mem J φ.val x)).ext rintro Y f ⟨s : F₁.val.obj (op Y), hs : φ.val.app _ s = F₂.val.map f.op x⟩ dsimp have h₁ := congr_fun (f₁.val.naturality f.op) x have h₂ := congr_fun (f₂.val.naturality f.op) x dsimp at h₁ h₂ rw [← h₁, ← h₂, ← hs] exact congr_fun (congr_app ((sheafToPresheaf J _).congr_map h) (op Y)) s instance epi_of_isLocallySurjective [IsLocallySurjective φ] : Epi φ := (sheafCompose J (forget A)).epi_of_epi_map inferInstance attribute [local instance] Types.instFunLike Types.instConcreteCategory in lemma isLocallySurjective_iff_epi {F G : Sheaf J (Type w)} (φ : F ⟶ G) [HasSheafify J (Type w)] : IsLocallySurjective φ ↔ Epi φ := by constructor · intro infer_instance · intro have := epi_of_epi_fac (Sheaf.toImage_ι φ) rw [isLocallySurjective_iff_isIso φ] apply isIso_of_mono_of_epi end Sheaf namespace Presieve.FamilyOfElements variable {R R' : Cᵒᵖ ⥤ Type w} (φ : R ⟶ R') {X : Cᵒᵖ} (r' : R'.obj X) attribute [local instance] Types.instFunLike Types.instConcreteCategory in /-- Given a morphism `φ : R ⟶ R'` of presheaves of types and `r' : R'.obj X`, this is the family of elements of `R` defined over the sieve `Presheaf.imageSieve φ r'` which sends a map in this sieve to an arbitrary choice of a preimage of the restriction of `r'`. -/ noncomputable def localPreimage : FamilyOfElements R (Presheaf.imageSieve φ r').arrows := fun _ f hf => Presheaf.localPreimage φ r' f hf attribute [local instance] Types.instFunLike Types.instConcreteCategory in lemma isAmalgamation_map_localPreimage : ((localPreimage φ r').map φ).IsAmalgamation r' := fun _ f hf => (Presheaf.app_localPreimage φ r' f hf).symm end Presieve.FamilyOfElements end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/GlobalSections.lean
import Mathlib.CategoryTheory.Sites.ConstantSheaf /-! # Global sections of sheaves In this file we define a global sections functor `Sheaf.Γ : Sheaf J A ⥤ A` and show that it is isomorphic to several other constructions when they exist, most notably evaluation of sheaves on a terminal object and `Functor.sectionsFunctor`. ## Main definitions / results * `HasGlobalSectionsFunctor J A`: typeclass stating that the constant sheaf functor `A ⥤ Sheaf J A` has a right-adjoint. * `Sheaf.Γ J A`: the global sections functor `Sheaf J A ⥤ A`, defined as the right-adjoint of the constant sheaf functor, whenever that exists. * `constantSheafΓAdj J A`: the adjunction between the constant sheaf functor and `Sheaf.Γ J A`. * `Sheaf.ΓNatIsoSheafSections J A hT`: on sites with a terminal object `T`, `Sheaf.Γ J A` exists and is isomorphic to the functor evaluating sheaves at `T`. * `Sheaf.ΓNatIsoLim J A`: when `A` has limits of shape `Cᵒᵖ`, `Sheaf.Γ J A` exists and is isomorphic to the functor taking each sheaf to the limit of its underlying presheaf. * `Sheaf.isLimitConeΓ F`: global sections are limits even when not all limits of shape `Cᵒᵖ` exist. * `Sheaf.ΓRes F U`: the restriction morphism from global sections of `F` to sections of `F` on `U`. * `Sheaf.natTransΓRes J A U`: the natural transformation from the global sections functor to the sections functor on `U`. * `Sheaf.ΓNatIsoSectionsFunctor J`: for sheaves of types, `Sheaf.Γ J A` is isomorphic to the functor taking each sheaf to the type of sections of its underlying presheaf in the sense of `Functor.sections`. * `Sheaf.ΓNatIsoCoyoneda J`: for sheaves of types, `Sheaf.Γ J A` is isomorphic to the coyoneda embedding of the terminal sheaf, i.e. the functor sending each sheaf `F` to the type of morphisms from the terminal sheaf to `F`. ## TODO * Generalise `Sheaf.ΓNatIsoSectionsFunctor` and `Sheaf.ΓNatIsoCoyoneda` from `Type max u v` to `Type max u v w`. This should hopefully be doable by relaxing the universe constraints of `instHasSheafifyOfHasFiniteLimits`. -/ universe u v w u₂ v₂ open CategoryTheory Limits Sheaf Opposite GrothendieckTopology namespace CategoryTheory variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) (A : Type u₂) [Category.{v₂} A] [HasWeakSheafify J A] /-- Typeclass stating that the constant sheaf functor has a right adjoint. This right adjoint will then be called the global sections functor and written `Sheaf.Γ`. -/ abbrev HasGlobalSectionsFunctor := (constantSheaf J A).IsLeftAdjoint /-- We define the global sections functor as the right-adjoint of the constant sheaf functor whenever it exists. -/ noncomputable def Sheaf.Γ [HasGlobalSectionsFunctor J A] : Sheaf J A ⥤ A := (constantSheaf J A).rightAdjoint /-- The constant sheaf functor is by definition left-adjoint to the global sections functor. -/ noncomputable def constantSheafΓAdj [HasGlobalSectionsFunctor J A] : constantSheaf J A ⊣ Γ J A := Adjunction.ofIsLeftAdjoint (constantSheaf J A) instance [HasGlobalSectionsFunctor J A] : (Γ J A).IsRightAdjoint := by unfold Γ; infer_instance /-- Sites with a terminal object admit a global sections functor. -/ instance hasGlobalSectionsFunctor_of_hasTerminal [HasTerminal C] : HasGlobalSectionsFunctor J A := ⟨_, ⟨constantSheafAdj J A terminalIsTerminal⟩⟩ /-- On sites with a terminal object, the global sections functor is isomorphic to the functor of sections on that object. -/ noncomputable def Sheaf.ΓNatIsoSheafSections [HasTerminal C] {T : C} (hT : IsTerminal T) : Γ J A ≅ (sheafSections J A).obj (op T) := (constantSheafΓAdj J A).rightAdjointUniq (constantSheafAdj J A hT) /-- Every site `C` admits a global sections functor for `A`-valued sheaves when `A` has limits of shape `Cᵒᵖ`. -/ instance hasGlobalSectionsFunctor_of_hasLimitsOfShape [HasLimitsOfShape Cᵒᵖ A] : HasGlobalSectionsFunctor J A := ⟨sheafToPresheaf J A ⋙ lim, ⟨constLimAdj.comp (sheafificationAdjunction J A)⟩⟩ /-- Global sections of sheaves are naturally isomorphic to the limits of the underlying presheaves. Note that while `HasLimitsOfShape Cᵒᵖ A` is needed here to talk about `lim` as a functor, global sections are still limits without it - see `Sheaf.isLimitConeΓ`. -/ noncomputable def Sheaf.ΓNatIsoLim [HasLimitsOfShape Cᵒᵖ A] : Γ J A ≅ sheafToPresheaf J A ⋙ lim := (constantSheafΓAdj J A).rightAdjointUniq (constLimAdj.comp (sheafificationAdjunction J A)) variable {J A} /-- Natural transformations from a constant presheaf into a sheaf correspond to morphisms to its global sections. -/ noncomputable def Sheaf.ΓHomEquiv [HasGlobalSectionsFunctor J A] {X : A} {F : Sheaf J A} : ((Functor.const _).obj X ⟶ F.val) ≃ (X ⟶ (Γ J A).obj F) := ((sheafificationAdjunction J A).homEquiv _ _).symm.trans ((constantSheafΓAdj J A).homEquiv _ _) /-- Naturality lemma for `ΓHomEquiv` analogous to `Adjunction.homEquiv_naturality_left`. -/ lemma Sheaf.ΓHomEquiv_naturality_left [HasGlobalSectionsFunctor J A] {X' X : A} {F : Sheaf J A} (f : X' ⟶ X) (g : (Functor.const _).obj X ⟶ F.val) : ΓHomEquiv ((Functor.const _).map f ≫ g) = f ≫ ΓHomEquiv g := (congrArg _ ((sheafificationAdjunction J A).homEquiv_naturality_left_symm _ _)).trans ((constantSheafΓAdj J A).homEquiv_naturality_left _ _) /-- Naturality lemma for `ΓHomEquiv` analogous to `Adjunction.homEquiv_naturality_left_symm`. -/ lemma Sheaf.ΓHomEquiv_naturality_left_symm [HasGlobalSectionsFunctor J A] {X' X : A} {F : Sheaf J A} (f : X' ⟶ X) (g : X ⟶ (Γ J A).obj F) : ΓHomEquiv.symm (f ≫ g) = (Functor.const _).map f ≫ ΓHomEquiv.symm g := (congrArg _ ((constantSheafΓAdj J A).homEquiv_naturality_left_symm _ _)).trans ((sheafificationAdjunction J A).homEquiv_naturality_left _ _) /-- Naturality lemma for `ΓHomEquiv` analogous to `Adjunction.homEquiv_naturality_right`. -/ lemma Sheaf.ΓHomEquiv_naturality_right [HasGlobalSectionsFunctor J A] {X : A} {F F' : Sheaf J A} (f : (Functor.const _).obj X ⟶ F.val) (g : F ⟶ F') : ΓHomEquiv (f ≫ g.val) = ΓHomEquiv f ≫ (Γ J A).map g := (congrArg _ ((sheafificationAdjunction J A).homEquiv_naturality_right_symm _ _)).trans ((constantSheafΓAdj J A).homEquiv_naturality_right _ _) /-- Naturality lemma for `ΓHomEquiv` analogous to `Adjunction.homEquiv_naturality_right_symm`. -/ lemma Sheaf.ΓHomEquiv_naturality_right_symm [HasGlobalSectionsFunctor J A] {X : A} {F F' : Sheaf J A} (f : X ⟶ (Γ J A).obj F) (g : F ⟶ F') : ΓHomEquiv.symm (f ≫ (Γ J A).map g) = ΓHomEquiv.symm f ≫ g.val := (congrArg _ ((constantSheafΓAdj J A).homEquiv_naturality_right_symm _ _)).trans ((sheafificationAdjunction J A).homEquiv_naturality_right _ _) /-- The cone over a given sheaf whose cone point are the global sections and whose components are the restriction maps. -/ @[simps pt] noncomputable def Sheaf.coneΓ [HasGlobalSectionsFunctor J A] (F : Sheaf J A) : Cone F.val where pt := (Γ J A).obj F π := ΓHomEquiv.symm (𝟙 _) /-- The global sections cone `Sheaf.coneΓ` is limiting - that is, global sections are limits even when not all limits of shape `Cᵒᵖ` exist in `A`. -/ noncomputable def Sheaf.isLimitConeΓ [HasGlobalSectionsFunctor J A] (F : Sheaf J A) : IsLimit F.coneΓ where lift c := F.ΓHomEquiv c.π fac c j := by suffices h : ((Functor.const Cᵒᵖ).map (ΓHomEquiv c.π)) ≫ F.coneΓ.π = c.π from congr_app h j simp [coneΓ, ← ΓHomEquiv_naturality_left_symm] uniq c f hf := by replace hf : ((Functor.const Cᵒᵖ).map f) ≫ F.coneΓ.π = c.π := by ext j; exact hf j simpa [coneΓ, ← ΓHomEquiv_naturality_left_symm, Equiv.symm_apply_eq] using hf /-- The restriction map from global sections of `F` to sections on `U`. -/ noncomputable def Sheaf.ΓRes [HasGlobalSectionsFunctor J A] (F : Sheaf J A) (U : Cᵒᵖ) : (Γ J A).obj F ⟶ F.val.obj U := F.coneΓ.π.app U @[reassoc (attr := simp)] lemma Sheaf.ΓRes_map [HasGlobalSectionsFunctor J A] (F : Sheaf J A) {V U : Cᵒᵖ} (f : U ⟶ V) : F.ΓRes U ≫ F.val.map f = F.ΓRes V := F.coneΓ.w f @[simp] lemma Sheaf.coneΓ_π_app [HasGlobalSectionsFunctor J A] (F : Sheaf J A) (U : Cᵒᵖ) : F.coneΓ.π.app U = F.ΓRes U := rfl lemma Sheaf.ΓRes_naturality [HasGlobalSectionsFunctor J A] {F G : Sheaf J A} (f : F ⟶ G) (U : Cᵒᵖ) : (Γ J A).map f ≫ ΓRes G U = ΓRes F U ≫ f.val.app U := by refine .trans ?_ <| congr_app (ΓHomEquiv_naturality_right_symm _ _) U exact (congr_app (ΓHomEquiv_naturality_left_symm ((Γ J A).map f) (𝟙 _)) U).symm.trans (by simp) variable (J A) /-- The natural transformation from the global sections functor to the sections functor on any object `U`. -/ @[simps!] noncomputable def Sheaf.natTransΓRes [HasGlobalSectionsFunctor J A] (U : Cᵒᵖ) : Γ J A ⟶ (sheafSections J A).obj U where app F := ΓRes F U naturality _ _ f := ΓRes_naturality f U -- this is currently needed to obtain the instance `HasSheafify J (Type max u v)`. attribute [local instance] CategoryTheory.Types.instConcreteCategory attribute [local instance] CategoryTheory.Types.instFunLike /-- Global sections of a sheaf of types correspond to sections of the underlying presheaf. -/ noncomputable def Sheaf.ΓObjEquivSections [HasWeakSheafify J (Type w)] [HasGlobalSectionsFunctor J (Type w)] (F : Sheaf J (Type w)) : (Γ J (Type w)).obj F ≃ F.val.sections := (Equiv.trans (by exact (Equiv.funUnique PUnit _).symm) ΓHomEquiv.symm).trans (F.val.sectionsEquivHom PUnit).symm lemma Sheaf.ΓObjEquivSections_naturality [HasWeakSheafify J (Type w)] [HasGlobalSectionsFunctor J (Type w)] {F G : Sheaf J (Type w)} (f : F ⟶ G) (x : (Γ J _).obj F) : (ΓObjEquivSections J G) ((Γ J _).map f x) = (Functor.sectionsFunctor _).map f.val ((ΓObjEquivSections J F) x) := by dsimp [ΓObjEquivSections] exact (congr_arg _ (ΓHomEquiv_naturality_right_symm _ _)).trans (Functor.sectionsEquivHom_naturality_symm _ _ _) lemma Sheaf.ΓObjEquivSections_naturality_symm [HasWeakSheafify J (Type w)] [HasGlobalSectionsFunctor J (Type w)] {F G : Sheaf J (Type w)} (f : F ⟶ G) (x : F.val.sections) : (ΓObjEquivSections J G).symm ((Functor.sectionsFunctor _).map f.val x) = (Γ J _).map f ((ΓObjEquivSections J F).symm x) := congr_fun (ΓHomEquiv_naturality_right (F.val.sectionsEquivHom _ x) f) _ /-- For sheaves of types, the global sections functor is isomorphic to the sections functor on presheaves. -/ noncomputable def Sheaf.ΓNatIsoSectionsFunctor : Γ J (Type max u v) ≅ sheafToPresheaf J _ ⋙ Functor.sectionsFunctor _ := NatIso.ofComponents (fun F ↦ (ΓObjEquivSections J F).toIso) fun f ↦ by ext x exact ΓObjEquivSections_naturality J f x /-- Global sections of a sheaf of types `F` correspond to morphisms from a terminal sheaf to `F`. We use the constant sheaf on a singleton type as a specific choice of terminal sheaf here. -/ noncomputable def Sheaf.ΓObjEquivHom [HasWeakSheafify J (Type w)] [HasGlobalSectionsFunctor J (Type w)] (F : Sheaf J (Type w)) (X : Type w) [Unique X] : (Γ J (Type w)).obj F ≃ ((constantSheaf J (Type w)).obj X ⟶ F) := (Equiv.funUnique X _).symm.trans ((constantSheafΓAdj J (Type w)).homEquiv _ _).symm lemma Sheaf.ΓObjEquivHom_naturality [HasWeakSheafify J (Type w)] [HasGlobalSectionsFunctor J (Type w)] (X : Type w) [Unique X] {F G : Sheaf J (Type w)} (f : F ⟶ G) (x : (Γ J _).obj F) : (ΓObjEquivHom J G X) ((Γ J _).map f x) = (ΓObjEquivHom J F X) x ≫ f := (constantSheafΓAdj J _).homEquiv_naturality_right_symm _ _ lemma Sheaf.ΓObjEquivHom_naturality_symm [HasWeakSheafify J (Type w)] [HasGlobalSectionsFunctor J (Type w)] {X : Type w} [Unique X] {F G : Sheaf J (Type w)} (f : F ⟶ G) (x : (constantSheaf J _).obj X ⟶ F) : (ΓObjEquivHom J G X).symm (x ≫ f) = (Γ J _).map f ((ΓObjEquivHom J F X).symm x) := congr_fun ((constantSheafΓAdj J _).homEquiv_naturality_right x f) default /-- For sheaves of types, the global sections functor is isomorphic to the covariant hom functor of the terminal sheaf. -/ noncomputable def Sheaf.ΓNatIsoCoyoneda (X : Type max u v) [Unique X] : Γ J (Type max u v) ≅ coyoneda.obj (op ((constantSheaf J _).obj X)) := NatIso.ofComponents (fun F ↦ (F.ΓObjEquivHom J X).toIso) fun f ↦ by ext x exact ΓObjEquivHom_naturality J X f x end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/EffectiveEpimorphic.lean
import Mathlib.CategoryTheory.Sites.Sieves import Mathlib.CategoryTheory.EffectiveEpi.Basic /-! # Effective epimorphic sieves We define the notion of effective epimorphic (pre)sieves and provide some API for relating the notion with the notions of effective epimorphism and effective epimorphic family. More precisely, if `f` is a morphism, then `f` is an effective epi if and only if the sieve it generates is effective epimorphic; see `CategoryTheory.Sieve.effectiveEpimorphic_singleton`. The analogous statement for a family of morphisms is in the theorem `CategoryTheory.Sieve.effectiveEpimorphic_family`. -/ namespace CategoryTheory open Limits variable {C : Type*} [Category C] /-- A sieve is effective epimorphic if the associated cocone is a colimit cocone. -/ def Sieve.EffectiveEpimorphic {X : C} (S : Sieve X) : Prop := Nonempty (IsColimit (S : Presieve X).cocone) /-- A presieve is effective epimorphic if the cocone associated to the sieve it generates is a colimit cocone. -/ abbrev Presieve.EffectiveEpimorphic {X : C} (S : Presieve X) : Prop := (Sieve.generate S).EffectiveEpimorphic /-- The sieve of morphisms which factor through a given morphism `f`. This is equal to `Sieve.generate (Presieve.singleton f)`, but has more convenient definitional properties. -/ def Sieve.generateSingleton {X Y : C} (f : Y ⟶ X) : Sieve X where arrows Z := { g | ∃ (e : Z ⟶ Y), e ≫ f = g } downward_closed := by rintro W Z g ⟨e,rfl⟩ q exact ⟨q ≫ e, by simp⟩ lemma Sieve.generateSingleton_eq {X Y : C} (f : Y ⟶ X) : Sieve.generate (Presieve.singleton f) = Sieve.generateSingleton f := by ext Z g constructor · rintro ⟨W,i,p,⟨⟩,rfl⟩ exact ⟨i,rfl⟩ · rintro ⟨g,h⟩ exact ⟨Y,g,f,⟨⟩,h⟩ /-- Implementation: This is a construction which will be used in the proof that the sieve generated by a single arrow is effective epimorphic if and only if the arrow is an effective epi. -/ def isColimitOfEffectiveEpiStruct {X Y : C} (f : Y ⟶ X) (Hf : EffectiveEpiStruct f) : IsColimit (Sieve.generateSingleton f : Presieve X).cocone := letI D := ObjectProperty.FullSubcategory fun T : Over X => Sieve.generateSingleton f T.hom letI F : D ⥤ _ := (Sieve.generateSingleton f).arrows.diagram { desc := fun S => Hf.desc (S.ι.app ⟨Over.mk f, ⟨𝟙 _, by simp⟩⟩) <| by intro Z g₁ g₂ h let Y' : D := ⟨Over.mk f, 𝟙 _, by simp⟩ let Z' : D := ⟨Over.mk (g₁ ≫ f), g₁, rfl⟩ let g₁' : Z' ⟶ Y' := Over.homMk g₁ let g₂' : Z' ⟶ Y' := Over.homMk g₂ (by simp [Y', Z', h]) change F.map g₁' ≫ _ = F.map g₂' ≫ _ simp only [Y', F, S.w] fac := by rintro S ⟨T,g,hT⟩ dsimp nth_rewrite 1 [← hT, Category.assoc, Hf.fac] let y : D := ⟨Over.mk f, 𝟙 _, by simp⟩ let x : D := ⟨Over.mk T.hom, g, hT⟩ let g' : x ⟶ y := Over.homMk g change F.map g' ≫ _ = _ rw [S.w] rfl uniq := by intro S m hm dsimp generalize_proofs h1 h2 apply Hf.uniq _ h2 exact hm ⟨Over.mk f, 𝟙 _, by simp⟩ } /-- Implementation: This is a construction which will be used in the proof that the sieve generated by a single arrow is effective epimorphic if and only if the arrow is an effective epi. -/ noncomputable def effectiveEpiStructOfIsColimit {X Y : C} (f : Y ⟶ X) (Hf : IsColimit (Sieve.generateSingleton f : Presieve X).cocone) : EffectiveEpiStruct f := let aux {W : C} (e : Y ⟶ W) (h : ∀ {Z : C} (g₁ g₂ : Z ⟶ Y), g₁ ≫ f = g₂ ≫ f → g₁ ≫ e = g₂ ≫ e) : Cocone (Sieve.generateSingleton f).arrows.diagram := { pt := W ι := { app := fun ⟨_,hT⟩ => hT.choose ≫ e naturality := by rintro ⟨A,hA⟩ ⟨B,hB⟩ (q : A ⟶ B) dsimp; simp only [← Category.assoc, Category.comp_id] apply h rw [Category.assoc, hB.choose_spec, hA.choose_spec, Over.w] } } { desc := fun {_} e h => Hf.desc (aux e h) fac := by intro W e h dsimp have := Hf.fac (aux e h) ⟨Over.mk f, 𝟙 _, by simp⟩ dsimp [aux] at this; rw [this]; clear this nth_rewrite 2 [← Category.id_comp e] apply h generalize_proofs hh rw [hh.choose_spec, Category.id_comp] uniq := by intro W e h m hm dsimp apply Hf.uniq (aux e h) rintro ⟨A,g,hA⟩ dsimp nth_rewrite 1 [← hA, Category.assoc, hm] apply h generalize_proofs hh rwa [hh.choose_spec] } theorem Sieve.effectiveEpimorphic_singleton {X Y : C} (f : Y ⟶ X) : (Presieve.singleton f).EffectiveEpimorphic ↔ (EffectiveEpi f) := by constructor · intro (h : Nonempty _) rw [Sieve.generateSingleton_eq] at h constructor apply Nonempty.map (effectiveEpiStructOfIsColimit _) h · rintro ⟨h⟩ change Nonempty _ rw [Sieve.generateSingleton_eq] apply Nonempty.map (isColimitOfEffectiveEpiStruct _) h /-- The sieve of morphisms which factor through a morphism in a given family. This is equal to `Sieve.generate (Presieve.ofArrows X π)`, but has more convenient definitional properties. -/ def Sieve.generateFamily {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) : Sieve B where arrows Y := { f | ∃ (a : α) (g : Y ⟶ X a), g ≫ π a = f } downward_closed := by rintro Y₁ Y₂ g₁ ⟨a,q,rfl⟩ e exact ⟨a, e ≫ q, by simp⟩ lemma Sieve.generateFamily_eq {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) : Sieve.generate (Presieve.ofArrows X π) = Sieve.generateFamily X π := by ext Y g constructor · rintro ⟨W, g, f, ⟨a⟩, rfl⟩ exact ⟨a, g, rfl⟩ · rintro ⟨a, g, rfl⟩ exact ⟨_, g, π a, ⟨a⟩, rfl⟩ /-- Implementation: This is a construction which will be used in the proof that the sieve generated by a family of arrows is effective epimorphic if and only if the family is an effective epi. -/ def isColimitOfEffectiveEpiFamilyStruct {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) (H : EffectiveEpiFamilyStruct X π) : IsColimit (Sieve.generateFamily X π : Presieve B).cocone := letI D := ObjectProperty.FullSubcategory fun T : Over B => Sieve.generateFamily X π T.hom letI F : D ⥤ _ := (Sieve.generateFamily X π).arrows.diagram { desc := fun S => H.desc (fun a => S.ι.app ⟨Over.mk (π a), ⟨a,𝟙 _, by simp⟩⟩) <| by intro Z a₁ a₂ g₁ g₂ h dsimp let A₁ : D := ⟨Over.mk (π a₁), a₁, 𝟙 _, by simp⟩ let A₂ : D := ⟨Over.mk (π a₂), a₂, 𝟙 _, by simp⟩ let Z' : D := ⟨Over.mk (g₁ ≫ π a₁), a₁, g₁, rfl⟩ let i₁ : Z' ⟶ A₁ := Over.homMk g₁ let i₂ : Z' ⟶ A₂ := Over.homMk g₂ change F.map i₁ ≫ _ = F.map i₂ ≫ _ simp only [F, A₁, A₂, S.w] fac := by intro S ⟨T, a, (g : T.left ⟶ X a), hT⟩ dsimp nth_rewrite 1 [← hT, Category.assoc, H.fac] let A : D := ⟨Over.mk (π a), a, 𝟙 _, by simp⟩ let B : D := ⟨Over.mk T.hom, a, g, hT⟩ let i : B ⟶ A := Over.homMk g change F.map i ≫ _ = _ rw [S.w] rfl uniq := by intro S m hm; dsimp apply H.uniq intro a exact hm ⟨Over.mk (π a), a, 𝟙 _, by simp⟩ } /-- Implementation: This is a construction which will be used in the proof that the sieve generated by a family of arrows is effective epimorphic if and only if the family is an effective epi. -/ noncomputable def effectiveEpiFamilyStructOfIsColimit {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) (H : IsColimit (Sieve.generateFamily X π : Presieve B).cocone) : EffectiveEpiFamilyStruct X π := let aux {W : C} (e : (a : α) → (X a ⟶ W)) (h : ∀ {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂), g₁ ≫ π _ = g₂ ≫ π _ → g₁ ≫ e _ = g₂ ≫ e _) : Cocone (Sieve.generateFamily X π).arrows.diagram := { pt := W ι := { app := fun ⟨_,hT⟩ => hT.choose_spec.choose ≫ e hT.choose naturality := by intro ⟨A,a,(g₁ : A.left ⟶ _),ha⟩ ⟨B,b,(g₂ : B.left ⟶ _),hb⟩ (q : A ⟶ B) dsimp; rw [Category.comp_id, ← Category.assoc] apply h; rw [Category.assoc] generalize_proofs h1 h2 h3 h4 rw [h2.choose_spec, h4.choose_spec, Over.w] } } { desc := fun {_} e h => H.desc (aux e h) fac := by intro W e h a dsimp have := H.fac (aux e h) ⟨Over.mk (π a), a, 𝟙 _, by simp⟩ dsimp [aux] at this; rw [this]; clear this conv_rhs => rw [← Category.id_comp (e a)] apply h generalize_proofs h1 h2 rw [h2.choose_spec, Category.id_comp] uniq := by intro W e h m hm apply H.uniq (aux e h) rintro ⟨T, a, (g : T.left ⟶ _), ha⟩ dsimp nth_rewrite 1 [← ha, Category.assoc, hm] apply h generalize_proofs h1 h2 rwa [h2.choose_spec] } theorem Sieve.effectiveEpimorphic_family {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) : (Presieve.ofArrows X π).EffectiveEpimorphic ↔ EffectiveEpiFamily X π := by constructor · intro (h : Nonempty _) rw [Sieve.generateFamily_eq] at h constructor apply Nonempty.map (effectiveEpiFamilyStructOfIsColimit _ _) h · rintro ⟨h⟩ change Nonempty _ rw [Sieve.generateFamily_eq] apply Nonempty.map (isColimitOfEffectiveEpiFamilyStruct _ _) h end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/JointlySurjective.lean
import Mathlib.CategoryTheory.Sites.Precoverage import Mathlib.CategoryTheory.Limits.Types.Pullbacks /-! # The jointly surjective precoverage In the category of types, the jointly surjective precoverage has the jointly surjective families as coverings. We show that this precoverage is stable under the standard constructions. ## Notes See `Mathlib/CategoryTheory/Sites/Types.lean` for the Grothendieck topology of jointly surjective covers. -/ universe u namespace CategoryTheory open Limits namespace Types /-- The jointly surjective precoverage in the category of types has the jointly surjective families as coverings. -/ def jointlySurjectivePrecoverage : Precoverage (Type u) where coverings X R := ∀ x : X, ∃ (Y : Type u) (g : Y ⟶ X), R g ∧ x ∈ Set.range g lemma mem_jointlySurjectivePrecoverage_iff {X : Type u} {R : Presieve X} : R ∈ jointlySurjectivePrecoverage X ↔ ∀ x : X, ∃ (Y : Type u) (g : Y ⟶ X), R g ∧ x ∈ Set.range g := .rfl lemma singleton_mem_jointlySurjectivePrecoverage_iff {X Y : Type u} {f : X ⟶ Y} : Presieve.singleton f ∈ jointlySurjectivePrecoverage Y ↔ Function.Surjective f := by rw [mem_jointlySurjectivePrecoverage_iff] refine ⟨fun hf x ↦ ?_, fun hf x ↦ ⟨X, f, ⟨⟩, by simp [hf.range_eq]⟩⟩ obtain ⟨_, _, ⟨⟩, hx⟩ := hf x exact hx @[simp] lemma ofArrows_mem_jointlySurjectivePrecoverage_iff {X : Type u} {ι : Type*} {Y : ι → Type u} {f : ∀ i, Y i ⟶ X} : Presieve.ofArrows Y f ∈ jointlySurjectivePrecoverage X ↔ ∀ x, ∃ (i : ι), x ∈ Set.range (f i) := by refine ⟨fun h x ↦ ?_, fun h x ↦ ?_⟩ · obtain ⟨Y, g, ⟨i⟩, hx⟩ := h x use i · obtain ⟨i, hx⟩ := h x use Y i, f i, ⟨i⟩ instance : jointlySurjectivePrecoverage.HasIsos where mem_coverings_of_isIso {S T} f hf x := by use S, f, ⟨⟩ exact surjective_of_epi f x instance : jointlySurjectivePrecoverage.IsStableUnderComposition where comp_mem_coverings {ι} S X f hf σ Y g hg := by simp_rw [ofArrows_mem_jointlySurjectivePrecoverage_iff] at hf hg ⊢ intro x obtain ⟨i, y, rfl⟩ := hf x obtain ⟨j, z, rfl⟩ := hg i y use ⟨i, j⟩, z simp instance : jointlySurjectivePrecoverage.IsStableUnderSup where sup_mem_coverings {X} R S hR _ x := by obtain ⟨Y, f, hf, hx⟩ := hR x use Y, f, .inl hf end Types variable {C : Type*} [Category C] (F : C ⥤ Type u) lemma Presieve.mem_comap_jointlySurjectivePrecoverage_iff {X : C} {R : Presieve X} : R ∈ Types.jointlySurjectivePrecoverage.comap F X ↔ ∀ x : F.obj X, ∃ (Y : C) (f : Y ⟶ X), R f ∧ x ∈ Set.range (F.map f) := by rw [Precoverage.mem_comap_iff] refine ⟨fun h x ↦ ?_, fun h x ↦ ?_⟩ · obtain ⟨-, -, ⟨hf⟩, hi⟩ := h x exact ⟨_, _, hf, hi⟩ · obtain ⟨Y, g, hg, hi⟩ := h x exact ⟨_, _, ⟨hg⟩, hi⟩ lemma Presieve.ofArrows_mem_comap_jointlySurjectivePrecoverage_iff {X : C} {ι : Type*} {Y : ι → C} {f : ∀ i, Y i ⟶ X} : ofArrows Y f ∈ Types.jointlySurjectivePrecoverage.comap F X ↔ ∀ x : F.obj X, ∃ (i : ι), x ∈ Set.range (F.map (f i)) := by simp /-- The pullback of the jointly surjective precoverage of types to any category `C` via a (forgetful) functor `C ⥤ Type u` is stable under base change if the canonical map `F (X ×[Y] Z) ⟶ F(X) ×[F(Y)] F(Z)` is surjective. -/ lemma isStableUnderBaseChange_comap_jointlySurjectivePrecoverage (H : ∀ {X Y S : C} (f : X ⟶ S) (g : Y ⟶ S) [HasPullback f g], Function.Surjective (pullbackComparison F f g)) : (Types.jointlySurjectivePrecoverage.comap F).IsStableUnderBaseChange where mem_coverings_of_isPullback {ι} S X f hf Y g P p₁ p₂ h := by rw [Precoverage.mem_comap_iff, Presieve.map_ofArrows, Types.ofArrows_mem_jointlySurjectivePrecoverage_iff] at hf ⊢ intro x obtain ⟨i, hi⟩ := hf (F.map g x) have : HasPullback g (f i) := (h i).hasPullback use i have : F.map (p₁ i) = F.map ((h i).isoPullback.hom) ≫ pullbackComparison F g (f i) ≫ pullback.fst _ _ := by simp [← Functor.map_comp] rwa [this, types_comp, types_comp, Function.comp_assoc, Set.range_comp, Function.Surjective.range_eq <| (H _ _).comp (surjective_of_epi _), Set.image_univ, Types.range_pullbackFst] instance : Types.jointlySurjectivePrecoverage.IsStableUnderBaseChange := by rw [← Precoverage.comap_id Types.jointlySurjectivePrecoverage] apply isStableUnderBaseChange_comap_jointlySurjectivePrecoverage intro X Y S f g _ exact surjective_of_epi _ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/LeftExact.lean
import Mathlib.CategoryTheory.Sites.Limits import Mathlib.CategoryTheory.Limits.FilteredColimitCommutesFiniteLimit import Mathlib.CategoryTheory.Adhesive import Mathlib.CategoryTheory.Sites.ConcreteSheafification /-! # Left exactness of sheafification In this file we show that sheafification commutes with finite limits. -/ open CategoryTheory Limits Opposite universe s t w' w v u variable {C : Type u} [Category.{v} C] {J : GrothendieckTopology C} noncomputable section namespace CategoryTheory.GrothendieckTopology variable {D : Type w} [Category.{t} D] variable [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.Cover X), HasMultiequalizer (S.index P)] /-- An auxiliary definition to be used in the proof of the fact that `J.diagramFunctor D X` preserves limits. -/ @[simps] def coneCompEvaluationOfConeCompDiagramFunctorCompEvaluation {X : C} {K : Type s} [SmallCategory K] {F : K ⥤ Cᵒᵖ ⥤ D} {W : J.Cover X} (i : W.Arrow) (E : Cone (F ⋙ J.diagramFunctor D X ⋙ (evaluation (J.Cover X)ᵒᵖ D).obj (op W))) : Cone (F ⋙ (evaluation _ _).obj (op i.Y)) where pt := E.pt π := { app := fun k => E.π.app k ≫ Multiequalizer.ι (W.index (F.obj k)) i naturality := by intro a b f dsimp rw [Category.id_comp, Category.assoc, ← E.w f] dsimp [diagramNatTrans] simp only [Multiequalizer.lift_ι, Category.assoc] } /-- Auxiliary definition for `liftToDiagramLimitObj`. -/ def liftToDiagramLimitObjAux {X : C} {K : Type s} [SmallCategory K] [HasLimitsOfShape K D] {W : (J.Cover X)ᵒᵖ} (F : K ⥤ Cᵒᵖ ⥤ D) (E : Cone (F ⋙ J.diagramFunctor D X ⋙ (evaluation (J.Cover X)ᵒᵖ D).obj W)) (i : (unop W).Arrow) : E.pt ⟶ (limit F).obj (op i.Y) := (isLimitOfPreserves ((evaluation Cᵒᵖ D).obj (op i.Y)) (limit.isLimit F)).lift (coneCompEvaluationOfConeCompDiagramFunctorCompEvaluation i E) @[reassoc (attr := simp)] lemma liftToDiagramLimitObjAux_fac {X : C} {K : Type s} [SmallCategory K] [HasLimitsOfShape K D] {W : (J.Cover X)ᵒᵖ} (F : K ⥤ Cᵒᵖ ⥤ D) (E : Cone (F ⋙ J.diagramFunctor D X ⋙ (evaluation (J.Cover X)ᵒᵖ D).obj W)) (i : (unop W).Arrow) (k : K) : liftToDiagramLimitObjAux F E i ≫ (limit.π F k).app (op i.Y) = E.π.app k ≫ Multiequalizer.ι ((unop W).index (F.obj k)) i := IsLimit.fac _ _ _ /-- An auxiliary definition to be used in the proof of the fact that `J.diagramFunctor D X` preserves limits. -/ abbrev liftToDiagramLimitObj {X : C} {K : Type s} [SmallCategory K] [HasLimitsOfShape K D] {W : (J.Cover X)ᵒᵖ} (F : K ⥤ Cᵒᵖ ⥤ D) (E : Cone (F ⋙ J.diagramFunctor D X ⋙ (evaluation (J.Cover X)ᵒᵖ D).obj W)) : E.pt ⟶ (J.diagram (limit F) X).obj W := Multiequalizer.lift ((unop W).index (limit F)) E.pt (liftToDiagramLimitObjAux F E) (by intro i dsimp ext k dsimp simp only [Category.assoc, NatTrans.naturality, liftToDiagramLimitObjAux_fac_assoc] erw [Multiequalizer.condition] rfl) instance preservesLimit_diagramFunctor (X : C) (K : Type s) [SmallCategory K] [HasLimitsOfShape K D] (F : K ⥤ Cᵒᵖ ⥤ D) : PreservesLimit F (J.diagramFunctor D X) := preservesLimit_of_evaluation _ _ fun W => preservesLimit_of_preserves_limit_cone (limit.isLimit _) { lift := fun E => liftToDiagramLimitObj.{_, t, w, v, u} F E fac := by intro E k dsimp [diagramNatTrans] refine Multiequalizer.hom_ext _ _ _ (fun a => ?_) simp only [Multiequalizer.lift_ι, Multiequalizer.lift_ι_assoc, Category.assoc, liftToDiagramLimitObjAux_fac] uniq := by intro E m hm refine Multiequalizer.hom_ext _ _ _ (fun a => limit_obj_ext (fun j => ?_)) dsimp [liftToDiagramLimitObj] rw [Multiequalizer.lift_ι, Category.assoc, liftToDiagramLimitObjAux_fac, ← hm, Category.assoc] dsimp rw [limit.lift_π] dsimp } instance preservesLimitsOfShape_diagramFunctor (X : C) (K : Type s) [SmallCategory K] [HasLimitsOfShape K D] : PreservesLimitsOfShape K (J.diagramFunctor D X) := ⟨by apply preservesLimit_diagramFunctor.{s, t, w, v, u}⟩ instance preservesLimits_diagramFunctor (X : C) [HasLimitsOfSize.{max t u v, max t u v} D] : PreservesLimits (J.diagramFunctor D X) := by constructor intro _ _ apply preservesLimitsOfShape_diagramFunctor.{max t u v} variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] variable [HasForget.{t} D] variable [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ (forget D)] variable [∀ X : C, Small.{t, max u v} (J.Cover X)ᵒᵖ] /-- An auxiliary definition to be used in the proof that `J.plusFunctor D` commutes with finite limits. -/ def liftToPlusObjLimitObj {K : Type s} [SmallCategory K] [FinCategory K] [HasLimitsOfShape K D] [PreservesLimitsOfShape K (forget D)] [ReflectsLimitsOfShape K (forget D)] (F : K ⥤ Cᵒᵖ ⥤ D) (X : C) (S : Cone (F ⋙ J.plusFunctor D ⋙ (evaluation Cᵒᵖ D).obj (op X))) : S.pt ⟶ (J.plusObj (limit F)).obj (op X) := let x := (J.Cover X)ᵒᵖ let F' := F ⋙ J.diagramFunctor D X let e := colimitLimitIso (F ⋙ J.diagramFunctor D X) let t : J.diagram (limit F) X ≅ limit (F ⋙ J.diagramFunctor D X) := (isLimitOfPreserves (J.diagramFunctor D X) (limit.isLimit F)).conePointUniqueUpToIso (limit.isLimit _) let p : (J.plusObj (limit F)).obj (op X) ≅ colimit (limit (F ⋙ J.diagramFunctor D X)) := HasColimit.isoOfNatIso t let s : colimit (F ⋙ J.diagramFunctor D X).flip ≅ F ⋙ J.plusFunctor D ⋙ (evaluation Cᵒᵖ D).obj (op X) := NatIso.ofComponents (fun k => colimitObjIsoColimitCompEvaluation _ k) (by intro i j f rw [← Iso.eq_comp_inv, Category.assoc, ← Iso.inv_comp_eq] refine colimit.hom_ext (fun w => ?_) dsimp [plusMap] erw [colimit.ι_map_assoc, colimitObjIsoColimitCompEvaluation_ι_inv (F ⋙ J.diagramFunctor D X).flip w j, colimitObjIsoColimitCompEvaluation_ι_inv_assoc (F ⋙ J.diagramFunctor D X).flip w i] rw [← (colimit.ι (F ⋙ J.diagramFunctor D X).flip w).naturality] rfl) limit.lift _ S ≫ (HasLimit.isoOfNatIso s.symm).hom ≫ e.inv ≫ p.inv -- This lemma should not be used directly. Instead, one should use the fact that -- `J.plusFunctor D` preserves finite limits, along with the fact that -- evaluation preserves limits. theorem liftToPlusObjLimitObj_fac {K : Type s} [SmallCategory K] [FinCategory K] [HasLimitsOfShape K D] [PreservesLimitsOfShape K (forget D)] [ReflectsLimitsOfShape K (forget D)] (F : K ⥤ Cᵒᵖ ⥤ D) (X : C) (S : Cone (F ⋙ J.plusFunctor D ⋙ (evaluation Cᵒᵖ D).obj (op X))) (k) : liftToPlusObjLimitObj F X S ≫ (J.plusMap (limit.π F k)).app (op X) = S.π.app k := by dsimp only [liftToPlusObjLimitObj] rw [← (limit.isLimit (F ⋙ J.plusFunctor D ⋙ (evaluation Cᵒᵖ D).obj (op X))).fac S k, Category.assoc] congr 1 dsimp rw [Category.assoc, Category.assoc, ← Iso.eq_inv_comp, Iso.inv_comp_eq, Iso.inv_comp_eq] refine colimit.hom_ext (fun j => ?_) dsimp [plusMap] simp only [HasColimit.isoOfNatIso_ι_hom_assoc, ι_colimMap] dsimp [IsLimit.conePointUniqueUpToIso, HasLimit.isoOfNatIso, IsLimit.map] rw [limit.lift_π] dsimp rw [ι_colimitLimitIso_limit_π_assoc] simp_rw [← Category.assoc, ← NatTrans.comp_app] rw [limit.lift_π, Category.assoc] congr 1 rw [← Iso.comp_inv_eq] erw [colimit.ι_desc] rfl instance preservesLimitsOfShape_plusFunctor (K : Type t) [SmallCategory K] [FinCategory K] [HasLimitsOfShape K D] [PreservesLimitsOfShape K (forget D)] [ReflectsLimitsOfShape K (forget D)] : PreservesLimitsOfShape K (J.plusFunctor D) := by constructor; intro F; apply preservesLimit_of_evaluation; intro X apply preservesLimit_of_preserves_limit_cone (limit.isLimit F) refine ⟨fun S => liftToPlusObjLimitObj F X.unop S, ?_, ?_⟩ · intro S k apply liftToPlusObjLimitObj_fac · intro S m hm dsimp [liftToPlusObjLimitObj] simp_rw [← Category.assoc, Iso.eq_comp_inv, ← Iso.comp_inv_eq] refine limit.hom_ext (fun k => ?_) simp only [limit.lift_π, Category.assoc, ← hm] congr 1 refine colimit.hom_ext (fun k => ?_) dsimp [plusMap, plusObj] erw [colimit.ι_map, colimit.ι_desc_assoc, limit.lift_π] conv_lhs => dsimp simp only [Category.assoc] rw [ι_colimitLimitIso_limit_π_assoc] simp only [colimitObjIsoColimitCompEvaluation_ι_app_hom] conv_lhs => dsimp [IsLimit.conePointUniqueUpToIso] rw [← Category.assoc, ← NatTrans.comp_app, limit.lift_π] rfl instance preserveFiniteLimits_plusFunctor [HasFiniteLimits D] [PreservesFiniteLimits (forget D)] [(forget D).ReflectsIsomorphisms] : PreservesFiniteLimits (J.plusFunctor D) := by apply preservesFiniteLimits_of_preservesFiniteLimitsOfSize.{t} intro K _ _ have : ReflectsLimitsOfShape K (forget D) := reflectsLimitsOfShape_of_reflectsIsomorphisms apply preservesLimitsOfShape_plusFunctor instance preservesLimitsOfShape_sheafification (K : Type t) [SmallCategory K] [FinCategory K] [HasLimitsOfShape K D] [PreservesLimitsOfShape K (forget D)] [ReflectsLimitsOfShape K (forget D)] : PreservesLimitsOfShape K (J.sheafification D) := Limits.comp_preservesLimitsOfShape _ _ instance preservesFiniteLimits_sheafification [HasFiniteLimits D] [PreservesFiniteLimits (forget D)] [(forget D).ReflectsIsomorphisms] : PreservesFiniteLimits (J.sheafification D) := Limits.comp_preservesFiniteLimits _ _ end CategoryTheory.GrothendieckTopology namespace CategoryTheory section variable {D : Type w} [Category.{t} D] variable [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.Cover X), HasMultiequalizer (S.index P)] variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] variable {FD : D → D → Type*} {CD : D → Type t} variable [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{t} D FD] variable [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ (forget D)] variable [(forget D).ReflectsIsomorphisms] variable [∀ {X : C} (S : J.Cover X), PreservesLimitsOfShape (WalkingMulticospan S.shape) (forget D)] variable (K : Type w') variable [SmallCategory K] [FinCategory K] [HasLimitsOfShape K D] instance preservesLimitsOfShape_presheafToSheaf [PreservesLimits (forget D)] [∀ X : C, Small.{t, max u v} (J.Cover X)ᵒᵖ] : PreservesLimitsOfShape K (plusPlusSheaf J D) := by let e := (FinCategory.equivAsType K).symm.trans (AsSmall.equiv.{0, 0, t}) haveI : HasLimitsOfShape (AsSmall.{t} (FinCategory.AsType K)) D := Limits.hasLimitsOfShape_of_equivalence e haveI : FinCategory (AsSmall.{t} (FinCategory.AsType K)) := by constructor · change Fintype (ULift _) infer_instance · intro j j' change Fintype (ULift _) infer_instance refine @preservesLimitsOfShape_of_equiv _ _ _ _ _ _ _ _ e.symm _ (show _ from ?_) constructor; intro F; constructor; intro S hS; constructor apply isLimitOfReflects (sheafToPresheaf J D) have : ReflectsLimitsOfShape (AsSmall.{t} (FinCategory.AsType K)) (forget D) := reflectsLimitsOfShape_of_reflectsIsomorphisms apply isLimitOfPreserves (J.sheafification D) hS instance preservesFiniteLimits_presheafToSheaf [PreservesLimits (forget D)] [∀ X : C, Small.{t, max u v} (J.Cover X)ᵒᵖ] [HasFiniteLimits D] : PreservesFiniteLimits (plusPlusSheaf J D) := by apply preservesFiniteLimits_of_preservesFiniteLimitsOfSize.{t} intros infer_instance variable (J D) /-- `plusPlusSheaf` is isomorphic to an arbitrary choice of left adjoint. -/ def plusPlusSheafIsoPresheafToSheaf : plusPlusSheaf J D ≅ presheafToSheaf J D := (plusPlusAdjunction J D).leftAdjointUniq (sheafificationAdjunction J D) /-- `plusPlusFunctor` is isomorphic to `sheafification`. -/ def plusPlusFunctorIsoSheafification : J.sheafification D ≅ sheafification J D := Functor.isoWhiskerRight (plusPlusSheafIsoPresheafToSheaf J D) (sheafToPresheaf J D) /-- `plusPlus` is isomorphic to `sheafify`. -/ def plusPlusIsoSheafify (P : Cᵒᵖ ⥤ D) : J.sheafify P ≅ sheafify J P := (sheafToPresheaf J D).mapIso ((plusPlusSheafIsoPresheafToSheaf J D).app P) @[reassoc (attr := simp)] lemma toSheafify_plusPlusIsoSheafify_hom (P : Cᵒᵖ ⥤ D) : J.toSheafify P ≫ (plusPlusIsoSheafify J D P).hom = toSheafify J P := by convert Adjunction.unit_leftAdjointUniq_hom_app (plusPlusAdjunction J D) (sheafificationAdjunction J D) P ext1 P dsimp [GrothendieckTopology.toSheafify, plusPlusAdjunction] rw [Category.comp_id] instance [PreservesLimits (forget D)] [HasFiniteLimits D] [∀ X : C, Small.{t, max u v} (J.Cover X)ᵒᵖ] : HasSheafify J D := HasSheafify.mk' J D (plusPlusAdjunction J D) attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance : HasSheafify J (Type max u v) := by infer_instance end variable {D : Type w} [Category.{w'} D] instance [FinitaryExtensive D] [HasPullbacks D] [HasSheafify J D] : FinitaryExtensive (Sheaf J D) := finitaryExtensive_of_reflective (sheafificationAdjunction _ _) instance [Adhesive D] [HasPullbacks D] [HasPushouts D] [HasSheafify J D] : Adhesive (Sheaf J D) := adhesive_of_reflective (sheafificationAdjunction _ _) instance SheafOfTypes.finitary_extensive [HasSheafify J (Type w)] : FinitaryExtensive (Sheaf J (Type w)) := inferInstance instance SheafOfTypes.adhesive [HasSheafify J (Type w)] : Adhesive (Sheaf J (Type w)) := inferInstance instance SheafOfTypes.balanced [HasSheafify J (Type w)] : Balanced (Sheaf J (Type w)) := inferInstance end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/EpiMono.lean
import Mathlib.CategoryTheory.MorphismProperty.Concrete import Mathlib.CategoryTheory.Sites.LocallyBijective /-! # Morphisms of sheaves factor as a locally surjective followed by a locally injective morphism When morphisms in a concrete category `A` factor in a functorial manner as a surjective map followed by an injective map, we obtain that any morphism of sheaves in `Sheaf J A` factors in a functorial manner as a locally surjective morphism (which is epi) followed by a locally injective morphism (which is mono). Moreover, if we assume that the category of sheaves `Sheaf J A` is balanced (see `Sites.LeftExact`), then epimorphisms are exactly locally surjective morphisms. -/ universe w v' u' v u namespace CategoryTheory open Category ConcreteCategory Functor variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) (A : Type u') [Category.{v'} A] {FA : A → A → Type*} {CA : A → Type w} [∀ X Y, FunLike (FA X Y) (CA X) (CA Y)] [ConcreteCategory.{w} A FA] [HasFunctorialSurjectiveInjectiveFactorization A] [J.WEqualsLocallyBijective A] namespace Sheaf /-- The class of locally injective morphisms of sheaves, see `Sheaf.IsLocallyInjective`. -/ def locallyInjective : MorphismProperty (Sheaf J A) := fun _ _ f => IsLocallyInjective f /-- The class of locally surjective morphisms of sheaves, see `Sheaf.IsLocallySurjective`. -/ def locallySurjective : MorphismProperty (Sheaf J A) := fun _ _ f => IsLocallySurjective f section variable {A} variable (data : FunctorialSurjectiveInjectiveFactorizationData A) [HasWeakSheafify J A] /-- Given a functorial surjective/injective factorizations of morphisms in a concrete category `A`, this is the induced functorial locally surjective/locally injective factorization of morphisms in the category `Sheaf J A`. -/ noncomputable def functorialLocallySurjectiveInjectiveFactorization : (locallySurjective J A).FunctorialFactorizationData (locallyInjective J A) where Z := (sheafToPresheaf J A).mapArrow ⋙ (data.functorCategory Cᵒᵖ).Z ⋙ presheafToSheaf J A i := whiskerLeft Arrow.leftFunc (inv (sheafificationAdjunction J A).counit) ≫ whiskerLeft (sheafToPresheaf J A).mapArrow (whiskerRight (data.functorCategory Cᵒᵖ).i (presheafToSheaf J A)) p := whiskerLeft (sheafToPresheaf J A).mapArrow (whiskerRight (data.functorCategory Cᵒᵖ).p (presheafToSheaf J A)) ≫ whiskerLeft Arrow.rightFunc (sheafificationAdjunction J A).counit fac := by ext f : 2 dsimp simp only [assoc, ← Functor.map_comp_assoc, MorphismProperty.FunctorialFactorizationData.fac_app, NatIso.isIso_inv_app, IsIso.inv_comp_eq] exact (sheafificationAdjunction J A).counit.naturality f.hom hi _ := by dsimp [locallySurjective] rw [← isLocallySurjective_sheafToPresheaf_map_iff, Functor.map_comp, Presheaf.comp_isLocallySurjective_iff, isLocallySurjective_sheafToPresheaf_map_iff, Presheaf.isLocallySurjective_presheafToSheaf_map_iff] apply Presheaf.isLocallySurjective_of_surjective apply (data.functorCategory Cᵒᵖ).hi hp _ := by dsimp [locallyInjective] rw [← isLocallyInjective_sheafToPresheaf_map_iff, Functor.map_comp, Presheaf.isLocallyInjective_comp_iff, isLocallyInjective_sheafToPresheaf_map_iff, Presheaf.isLocallyInjective_presheafToSheaf_map_iff] apply Presheaf.isLocallyInjective_of_injective apply (data.functorCategory Cᵒᵖ).hp section variable (f : Arrow (Sheaf J A)) instance : IsLocallySurjective ((functorialLocallySurjectiveInjectiveFactorization J data).i.app f) := by apply (functorialLocallySurjectiveInjectiveFactorization J data).hi instance : IsLocallyInjective ((functorialLocallySurjectiveInjectiveFactorization J data).p.app f) := by apply (functorialLocallySurjectiveInjectiveFactorization J data).hp variable [J.HasSheafCompose (forget A)] instance : Epi ((functorialLocallySurjectiveInjectiveFactorization J data).i.app f) := by apply epi_of_isLocallySurjective instance : Mono ((functorialLocallySurjectiveInjectiveFactorization J data).p.app f) := by apply mono_of_isLocallyInjective end instance : (locallySurjective J A).HasFunctorialFactorization (locallyInjective J A) where nonempty_functorialFactorizationData := ⟨functorialLocallySurjectiveInjectiveFactorization J (MorphismProperty.functorialFactorizationData _ _)⟩ end section variable {J} variable [HasSheafify J A] [J.HasSheafCompose (forget A)] [Balanced (Sheaf J A)] variable {F G : Sheaf J A} (φ : F ⟶ G) lemma isLocallySurjective_iff_epi' : IsLocallySurjective φ ↔ Epi φ := by constructor · intro infer_instance · intro let data := (locallySurjective J A).factorizationData (locallyInjective J A) φ have : IsLocallySurjective data.i := data.hi have : IsLocallyInjective data.p := data.hp have : Epi data.p := epi_of_epi_fac data.fac have := mono_of_isLocallyInjective data.p have := isIso_of_mono_of_epi data.p rw [← data.fac] infer_instance end end Sheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/CoverPreserving.lean
import Mathlib.CategoryTheory.Functor.Flat import Mathlib.CategoryTheory.Sites.Continuous import Mathlib.Tactic.ApplyFun /-! # Cover-preserving functors between sites. In order to show that a functor is continuous, we define cover-preserving functors between sites as functors that push covering sieves to covering sieves. Then, a cover-preserving and compatible-preserving functor is continuous. ## Main definitions * `CategoryTheory.CoverPreserving`: a functor between sites is cover-preserving if it pushes covering sieves to covering sieves * `CategoryTheory.CompatiblePreserving`: a functor between sites is compatible-preserving if it pushes compatible families of elements to compatible families. ## Main results - `CategoryTheory.isContinuous_of_coverPreserving`: If `G : C ⥤ D` is cover-preserving and compatible-preserving, then `G` is a continuous functor, i.e. `G.op ⋙ -` as a functor `(Dᵒᵖ ⥤ A) ⥤ (Cᵒᵖ ⥤ A)` of presheaves maps sheaves to sheaves. ## References * [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.3. * https://stacks.math.columbia.edu/tag/00WU -/ universe w v₁ v₂ v₃ u₁ u₂ u₃ noncomputable section open CategoryTheory Opposite CategoryTheory.Presieve.FamilyOfElements CategoryTheory.Presieve CategoryTheory.Limits namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D) variable {A : Type u₃} [Category.{v₃} A] variable (J : GrothendieckTopology C) (K : GrothendieckTopology D) variable {L : GrothendieckTopology A} /-- A functor `G : (C, J) ⥤ (D, K)` between sites is *cover-preserving* if for all covering sieves `R` in `C`, `R.functorPushforward G` is a covering sieve in `D`. -/ structure CoverPreserving (G : C ⥤ D) : Prop where cover_preserve : ∀ {U : C} {S : Sieve U} (_ : S ∈ J U), S.functorPushforward G ∈ K (G.obj U) /-- The identity functor on a site is cover-preserving. -/ theorem idCoverPreserving : CoverPreserving J J (𝟭 _) := ⟨fun hS => by simpa using hS⟩ /-- The composition of two cover-preserving functors is cover-preserving. -/ theorem CoverPreserving.comp {F} (hF : CoverPreserving J K F) {G} (hG : CoverPreserving K L G) : CoverPreserving J L (F ⋙ G) := ⟨fun hS => by rw [Sieve.functorPushforward_comp] exact hG.cover_preserve (hF.cover_preserve hS)⟩ /-- A functor `G : (C, J) ⥤ (D, K)` between sites is called compatible preserving if for each compatible family of elements at `C` and valued in `G.op ⋙ ℱ`, and each commuting diagram `f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂`, `x g₁` and `x g₂` coincide when restricted via `fᵢ`. This is actually stronger than merely preserving compatible families because of the definition of `functorPushforward` used. -/ structure CompatiblePreserving (K : GrothendieckTopology D) (G : C ⥤ D) : Prop where compatible : ∀ (ℱ : Sheaf K (Type w)) {Z} {T : Presieve Z} {x : FamilyOfElements (G.op ⋙ ℱ.val) T} (_ : x.Compatible) {Y₁ Y₂} {X} (f₁ : X ⟶ G.obj Y₁) (f₂ : X ⟶ G.obj Y₂) {g₁ : Y₁ ⟶ Z} {g₂ : Y₂ ⟶ Z} (hg₁ : T g₁) (hg₂ : T g₂) (_ : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂), ℱ.val.map f₁.op (x g₁ hg₁) = ℱ.val.map f₂.op (x g₂ hg₂) section variable {J K} {G : C ⥤ D} (hG : CompatiblePreserving.{w} K G) (ℱ : Sheaf K (Type w)) {Z : C} variable {T : Presieve Z} {x : FamilyOfElements (G.op ⋙ ℱ.val) T} (h : x.Compatible) include hG h /-- `CompatiblePreserving` functors indeed preserve compatible families. -/ theorem Presieve.FamilyOfElements.Compatible.functorPushforward : (x.functorPushforward G).Compatible := by rintro Z₁ Z₂ W g₁ g₂ f₁' f₂' H₁ H₂ eq unfold FamilyOfElements.functorPushforward rcases getFunctorPushforwardStructure H₁ with ⟨X₁, f₁, h₁, hf₁, rfl⟩ rcases getFunctorPushforwardStructure H₂ with ⟨X₂, f₂, h₂, hf₂, rfl⟩ suffices ℱ.val.map (g₁ ≫ h₁).op (x f₁ hf₁) = ℱ.val.map (g₂ ≫ h₂).op (x f₂ hf₂) by simpa using this apply hG.compatible ℱ h _ _ hf₁ hf₂ simpa using eq @[simp] theorem CompatiblePreserving.apply_map {Y : C} {f : Y ⟶ Z} (hf : T f) : x.functorPushforward G (G.map f) (image_mem_functorPushforward G T hf) = x f hf := by unfold FamilyOfElements.functorPushforward rcases getFunctorPushforwardStructure (image_mem_functorPushforward G T hf) with ⟨X, g, f', hg, eq⟩ simpa using hG.compatible ℱ h f' (𝟙 _) hg hf (by simp [eq]) end open Limits.WalkingCospan theorem compatiblePreservingOfFlat {C : Type u₁} [Category.{v₁} C] {D : Type u₁} [Category.{v₁} D] (K : GrothendieckTopology D) (G : C ⥤ D) [RepresentablyFlat G] : CompatiblePreserving K G := by constructor intro ℱ Z T x hx Y₁ Y₂ X f₁ f₂ g₁ g₂ hg₁ hg₂ e -- First, `f₁` and `f₂` form a cone over `cospan g₁ g₂ ⋙ u`. let c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) /- This can then be viewed as a cospan of structured arrows, and we may obtain an arbitrary cone over it since `StructuredArrow W u` is cofiltered. Then, it suffices to prove that it is compatible when restricted onto `u(c'.X.right)`. -/ let c' := IsCofiltered.cone (c.toStructuredArrow ⋙ StructuredArrow.pre _ _ _) have eq₁ : f₁ = (c'.pt.hom ≫ G.map (c'.π.app left).right) ≫ eqToHom (by simp) := by simp [c] have eq₂ : f₂ = (c'.pt.hom ≫ G.map (c'.π.app right).right) ≫ eqToHom (by simp) := by simp [c] conv_lhs => rw [eq₁] conv_rhs => rw [eq₂] simp only [c, op_comp, Functor.map_comp, types_comp_apply, eqToHom_op, eqToHom_map] apply congr_arg -- Porting note: was `congr 1` which for some reason doesn't do anything here -- despite goal being of the form f a = f b, with f=`ℱ.val.map (Quiver.Hom.op c'.pt.hom)` /- Since everything now falls in the image of `u`, the result follows from the compatibility of `x` in the image of `u`. -/ injection c'.π.naturality WalkingCospan.Hom.inl with _ e₁ injection c'.π.naturality WalkingCospan.Hom.inr with _ e₂ exact hx (c'.π.app left).right (c'.π.app right).right hg₁ hg₂ (e₁.symm.trans e₂) theorem compatiblePreservingOfDownwardsClosed (F : C ⥤ D) [F.Full] [F.Faithful] (hF : ∀ {c : C} {d : D} (_ : d ⟶ F.obj c), Σ c', F.obj c' ≅ d) : CompatiblePreserving K F := by constructor introv hx he obtain ⟨X', e⟩ := hF f₁ apply (ℱ.1.mapIso e.op).toEquiv.injective simp only [Iso.op_hom, Iso.toEquiv_fun, ℱ.1.mapIso_hom, ← FunctorToTypes.map_comp_apply] simpa using hx (F.preimage <| e.hom ≫ f₁) (F.preimage <| e.hom ≫ f₂) hg₁ hg₂ (F.map_injective <| by simpa using he) variable {F J K} /-- If `F` is cover-preserving and compatible-preserving, then `F` is a continuous functor. -/ @[stacks 00WW "This is basically this Stacks entry."] lemma Functor.isContinuous_of_coverPreserving (hF₁ : CompatiblePreserving.{w} K F) (hF₂ : CoverPreserving J K F) : Functor.IsContinuous.{w} F J K where op_comp_isSheaf_of_types G X S hS x hx := by apply existsUnique_of_exists_of_unique · have H := (isSheaf_iff_isSheaf_of_type _ _).1 G.2 _ (hF₂.cover_preserve hS) exact ⟨H.amalgamate (x.functorPushforward F) (hx.functorPushforward hF₁), fun V f hf => (H.isAmalgamation (hx.functorPushforward hF₁) (F.map f) _).trans (hF₁.apply_map _ hx hf)⟩ · intro y₁ y₂ hy₁ hy₂ apply (((isSheaf_iff_isSheaf_of_type _ _).1 G.2).isSeparated _ (hF₂.cover_preserve hS)).ext rintro Y _ ⟨Z, g, h, hg, rfl⟩ dsimp simp only [Functor.map_comp, types_comp_apply] have H := (hy₁ g hg).trans (hy₂ g hg).symm dsimp at H rw [H] end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Canonical.lean
import Mathlib.CategoryTheory.Sites.Sheaf import Mathlib.CategoryTheory.Sites.Whiskering /-! # The canonical topology on a category We define the finest (largest) Grothendieck topology for which a given presheaf `P` is a sheaf. This is well defined since if `P` is a sheaf for a topology `J`, then it is a sheaf for any coarser (smaller) topology. Nonetheless we define the topology explicitly by specifying its sieves: A sieve `S` on `X` is covering for `finestTopologySingle P` iff for any `f : Y ⟶ X`, `P` satisfies the sheaf axiom for `S.pullback f`. Showing that this is a genuine Grothendieck topology (namely that it satisfies the transitivity axiom) forms the bulk of this file. This generalises to a set of presheaves, giving the topology `finestTopology Ps` which is the finest topology for which every presheaf in `Ps` is a sheaf. Using `Ps` as the set of representable presheaves defines the `canonicalTopology`: the finest topology for which every representable is a sheaf. A Grothendieck topology is called `Subcanonical` if it is smaller than the canonical topology, equivalently it is subcanonical iff every representable presheaf is a sheaf. ## References * https://ncatlab.org/nlab/show/canonical+topology * https://ncatlab.org/nlab/show/subcanonical+coverage * https://stacks.math.columbia.edu/tag/00Z9 * https://math.stackexchange.com/a/358709/ -/ universe w v u namespace CategoryTheory open CategoryTheory Category Limits Sieve variable {C : Type u} [Category.{v} C] namespace Sheaf variable {P : Cᵒᵖ ⥤ Type v} {X : C} (J : GrothendieckTopology C) /-- To show `P` is a sheaf for the binding of `U` with `B`, it suffices to show that `P` is a sheaf for `U`, that `P` is a sheaf for each sieve in `B`, and that it is separated for any pullback of any sieve in `B`. This is mostly an auxiliary lemma to show `isSheafFor_trans`. Adapted from [Elephant], Lemma C2.1.7(i) with suggestions as mentioned in https://math.stackexchange.com/a/358709/ -/ theorem isSheafFor_bind (P : Cᵒᵖ ⥤ Type v) (U : Sieve X) (B : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, U f → Sieve Y) (hU : Presieve.IsSheafFor P (U : Presieve X)) (hB : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄ (hf : U f), Presieve.IsSheafFor P (B hf : Presieve Y)) (hB' : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄ (h : U f) ⦃Z⦄ (g : Z ⟶ Y), Presieve.IsSeparatedFor P (((B h).pullback g) : Presieve Z)) : Presieve.IsSheafFor P (Sieve.bind (U : Presieve X) B : Presieve X) := by intro s hs let y : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄ (hf : U f), Presieve.FamilyOfElements P (B hf : Presieve Y) := fun Y f hf Z g hg => s _ (Presieve.bind_comp _ _ hg) have hy : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄ (hf : U f), (y hf).Compatible := by intro Y f H Y₁ Y₂ Z g₁ g₂ f₁ f₂ hf₁ hf₂ comm apply hs apply reassoc_of% comm let t : Presieve.FamilyOfElements P (U : Presieve X) := fun Y f hf => (hB hf).amalgamate (y hf) (hy hf) have ht : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄ (hf : U f), (y hf).IsAmalgamation (t f hf) := fun Y f hf => (hB hf).isAmalgamation _ have hT : t.Compatible := by rw [Presieve.compatible_iff_sieveCompatible] intro Z W f h hf apply (hB (U.downward_closed hf h)).isSeparatedFor.ext intro Y l hl apply (hB' hf (l ≫ h)).ext intro M m hm have : bind U B (m ≫ l ≫ h ≫ f) := by simpa using (Presieve.bind_comp f hf hm : bind U B _) trans s (m ≫ l ≫ h ≫ f) this · have := ht (U.downward_closed hf h) _ ((B _).downward_closed hl m) rw [op_comp, FunctorToTypes.map_comp_apply] at this grind · have h : s _ _ = _ := (ht hf _ hm).symm -- Porting note: this was done by `simp only [assoc] at` conv_lhs at h => congr; rw [assoc, assoc] rw [h] simp only [op_comp, assoc, FunctorToTypes.map_comp_apply] refine ⟨hU.amalgamate t hT, ?_, ?_⟩ · rintro Z _ ⟨Y, f, g, hg, hf, rfl⟩ rw [op_comp, FunctorToTypes.map_comp_apply, Presieve.IsSheafFor.valid_glue _ _ _ hg] apply ht hg _ hf · intro y hy apply hU.isSeparatedFor.ext intro Y f hf apply (hB hf).isSeparatedFor.ext intro Z g hg rw [← FunctorToTypes.map_comp_apply, ← op_comp, hy _ (Presieve.bind_comp _ _ hg), hU.valid_glue _ _ hf, ht hf _ hg] /-- Given two sieves `R` and `S`, to show that `P` is a sheaf for `S`, we can show: * `P` is a sheaf for `R` * `P` is a sheaf for the pullback of `S` along any arrow in `R` * `P` is separated for the pullback of `R` along any arrow in `S`. This is mostly an auxiliary lemma to construct `finestTopology`. Adapted from [Elephant], Lemma C2.1.7(ii) with suggestions as mentioned in https://math.stackexchange.com/a/358709 -/ theorem isSheafFor_trans (P : Cᵒᵖ ⥤ Type v) (R S : Sieve X) (hR : Presieve.IsSheafFor P (R : Presieve X)) (hR' : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄ (_ : S f), Presieve.IsSeparatedFor P (R.pullback f : Presieve Y)) (hS : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄ (_ : R f), Presieve.IsSheafFor P (S.pullback f : Presieve Y)) : Presieve.IsSheafFor P (S : Presieve X) := by have : (bind R fun Y f _ => S.pullback f : Presieve X) ≤ S := by rintro Z f ⟨W, f, g, hg, hf : S _, rfl⟩ apply hf apply Presieve.isSheafFor_subsieve_aux P this · apply isSheafFor_bind _ _ _ hR hS intro Y f hf Z g rw [← pullback_comp] apply (hS (R.downward_closed hf _)).isSeparatedFor · intro Y f hf have : Sieve.pullback f (bind R fun T (k : T ⟶ X) (_ : R k) => pullback k S) = R.pullback f := by ext Z g constructor · rintro ⟨W, k, l, hl, _, comm⟩ rw [pullback_apply, ← comm] simp [hl] · intro a refine ⟨Z, 𝟙 Z, _, a, ?_⟩ simp [hf] rw [this] apply hR' hf /-- Construct the finest (largest) Grothendieck topology for which the given presheaf is a sheaf. -/ @[stacks 00Z9 "This is a special case of the Stacks entry, but following a different proof (see the Stacks comments)."] def finestTopologySingle (P : Cᵒᵖ ⥤ Type v) : GrothendieckTopology C where sieves X S := ∀ (Y) (f : Y ⟶ X), Presieve.IsSheafFor P (S.pullback f : Presieve Y) top_mem' X Y f := by rw [Sieve.pullback_top] exact Presieve.isSheafFor_top_sieve P pullback_stable' X Y S f hS Z g := by rw [← pullback_comp] apply hS transitive' X S hS R hR Z g := by -- This is the hard part of the construction, showing that the given set of sieves satisfies -- the transitivity axiom. refine isSheafFor_trans P (pullback g S) _ (hS Z g) ?_ ?_ · intro Y f _ rw [← pullback_comp] apply (hS _ _).isSeparatedFor · intro Y f hf have := hR hf _ (𝟙 _) rw [pullback_id, pullback_comp] at this apply this /-- Construct the finest (largest) Grothendieck topology for which all the given presheaves are sheaves. -/ @[stacks 00Z9 "Equal to that Stacks construction"] def finestTopology (Ps : Set (Cᵒᵖ ⥤ Type v)) : GrothendieckTopology C := sInf (finestTopologySingle '' Ps) /-- Check that if `P ∈ Ps`, then `P` is indeed a sheaf for the finest topology on `Ps`. -/ theorem sheaf_for_finestTopology (Ps : Set (Cᵒᵖ ⥤ Type v)) (h : P ∈ Ps) : Presieve.IsSheaf (finestTopology Ps) P := fun X S hS => by simpa using hS _ ⟨⟨_, _, ⟨_, h, rfl⟩, rfl⟩, rfl⟩ _ (𝟙 _) /-- Check that if each `P ∈ Ps` is a sheaf for `J`, then `J` is a subtopology of `finestTopology Ps`. -/ theorem le_finestTopology (Ps : Set (Cᵒᵖ ⥤ Type v)) (J : GrothendieckTopology C) (hJ : ∀ P ∈ Ps, Presieve.IsSheaf J P) : J ≤ finestTopology Ps := by rintro X S hS _ ⟨⟨_, _, ⟨P, hP, rfl⟩, rfl⟩, rfl⟩ intro Y f -- this can't be combined with the previous because the `subst` is applied at the end exact hJ P hP (S.pullback f) (J.pullback_stable f hS) /-- The `canonicalTopology` on a category is the finest (largest) topology for which every representable presheaf is a sheaf. -/ @[stacks 00ZA] def canonicalTopology (C : Type u) [Category.{v} C] : GrothendieckTopology C := finestTopology (Set.range yoneda.obj) /-- `yoneda.obj X` is a sheaf for the canonical topology. -/ theorem isSheaf_yoneda_obj (X : C) : Presieve.IsSheaf (canonicalTopology C) (yoneda.obj X) := fun _ _ hS => sheaf_for_finestTopology _ (Set.mem_range_self _) _ hS /-- A representable functor is a sheaf for the canonical topology. -/ theorem isSheaf_of_isRepresentable (P : Cᵒᵖ ⥤ Type v) [P.IsRepresentable] : Presieve.IsSheaf (canonicalTopology C) P := Presieve.isSheaf_iso (canonicalTopology C) P.reprW (isSheaf_yoneda_obj _) end Sheaf namespace GrothendieckTopology open Sheaf /-- A subcanonical topology is a topology which is smaller than the canonical topology. Equivalently, a topology is subcanonical iff every representable is a sheaf. -/ class Subcanonical (J : GrothendieckTopology C) : Prop where le_canonical : J ≤ canonicalTopology C lemma le_canonical (J : GrothendieckTopology C) [Subcanonical J] : J ≤ canonicalTopology C := Subcanonical.le_canonical instance : (canonicalTopology C).Subcanonical where le_canonical := le_rfl namespace Subcanonical /-- If every functor `yoneda.obj X` is a `J`-sheaf, then `J` is subcanonical. -/ theorem of_isSheaf_yoneda_obj (J : GrothendieckTopology C) (h : ∀ X, Presieve.IsSheaf J (yoneda.obj X)) : Subcanonical J where le_canonical := le_finestTopology _ _ (by rintro P ⟨X, rfl⟩; apply h) /-- If `J` is subcanonical, then any representable is a `J`-sheaf. -/ theorem isSheaf_of_isRepresentable {J : GrothendieckTopology C} [Subcanonical J] (P : Cᵒᵖ ⥤ Type v) [P.IsRepresentable] : Presieve.IsSheaf J P := Presieve.isSheaf_of_le _ J.le_canonical (Sheaf.isSheaf_of_isRepresentable P) variable {J : GrothendieckTopology C} end Subcanonical variable (J : GrothendieckTopology C) /-- If `J` is subcanonical, we obtain a "Yoneda" functor from the defining site into the sheaf category. -/ @[simps] def yoneda [J.Subcanonical] : C ⥤ Sheaf J (Type v) where obj X := ⟨CategoryTheory.yoneda.obj X, by rw [isSheaf_iff_isSheaf_of_type] apply Subcanonical.isSheaf_of_isRepresentable⟩ map f := ⟨CategoryTheory.yoneda.map f⟩ /-- Variant of the Yoneda embedding which allows a raise in the universe level for the category of types. -/ @[pp_with_univ, simps!] def uliftYoneda [J.Subcanonical] : C ⥤ Sheaf J (Type max v w) := J.yoneda ⋙ sheafCompose J uliftFunctor.{w} @[deprecated (since := "2025-11-10")] alias yonedaULift := uliftYoneda variable [Subcanonical J] /-- The yoneda embedding into the presheaf category factors through the one to the sheaf category. -/ def yonedaCompSheafToPresheaf : J.yoneda ⋙ sheafToPresheaf J (Type v) ≅ CategoryTheory.yoneda := Iso.refl _ /-- The yoneda functor into the sheaf category is fully faithful -/ def yonedaFullyFaithful : (J.yoneda).FullyFaithful := Functor.FullyFaithful.ofCompFaithful (G := sheafToPresheaf J (Type v)) Yoneda.fullyFaithful instance : (J.yoneda).Full := (J.yonedaFullyFaithful).full instance : (J.yoneda).Faithful := (J.yonedaFullyFaithful).faithful end GrothendieckTopology end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Subsheaf.lean
import Mathlib.CategoryTheory.Elementwise import Mathlib.CategoryTheory.Limits.FunctorCategory.EpiMono import Mathlib.Tactic.CategoryTheory.Elementwise import Mathlib.CategoryTheory.Sites.ConcreteSheafification import Mathlib.CategoryTheory.Subpresheaf.Image import Mathlib.CategoryTheory.Subpresheaf.Sieves /-! # Subsheaf of types We define the sub(pre)sheaf of a type-valued presheaf. ## Main results - `CategoryTheory.Subpresheaf` : A subpresheaf of a presheaf of types. - `CategoryTheory.Subpresheaf.sheafify` : The sheafification of a subpresheaf as a subpresheaf. Note that this is a sheaf only when the whole sheaf is. - `CategoryTheory.Subpresheaf.sheafify_isSheaf` : The sheafification is a sheaf - `CategoryTheory.Subpresheaf.sheafifyLift` : The descent of a map into a sheaf to the sheafification. - `CategoryTheory.GrothendieckTopology.imageSheaf` : The image sheaf of a morphism. - `CategoryTheory.GrothendieckTopology.imageFactorization` : The image sheaf as a `Limits.imageFactorization`. -/ universe w v u open Opposite CategoryTheory namespace CategoryTheory variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) variable {F F' F'' : Cᵒᵖ ⥤ Type w} (G G' : Subpresheaf F) /-- Every subpresheaf of a separated presheaf is itself separated. -/ theorem Subpresheaf.isSeparated {J : GrothendieckTopology C} (h : Presieve.IsSeparated J F) : Presieve.IsSeparated J G.toPresheaf := fun _ S hS _ _ _ hx₁ hx₂ ↦ Subtype.ext <| h S hS _ _ _ (hx₁.map G.ι) (hx₂.map G.ι) /-- The sheafification of a subpresheaf as a subpresheaf. Note that this is a sheaf only when the whole presheaf is a sheaf. -/ def Subpresheaf.sheafify : Subpresheaf F where obj U := { s | G.sieveOfSection s ∈ J (unop U) } map := by rintro U V i s hs refine J.superset_covering ?_ (J.pullback_stable i.unop hs) intro _ _ h dsimp at h ⊢ rwa [← FunctorToTypes.map_comp_apply] theorem Subpresheaf.le_sheafify : G ≤ G.sheafify J := by intro U s hs change _ ∈ J _ convert J.top_mem U.unop rw [eq_top_iff] rintro V i - exact G.map i.op hs variable {J} theorem Subpresheaf.eq_sheafify (h : Presieve.IsSheaf J F) (hG : Presieve.IsSheaf J G.toPresheaf) : G = G.sheafify J := by apply (G.le_sheafify J).antisymm intro U s hs suffices ((hG _ hs).amalgamate _ (G.family_of_elements_compatible s)).1 = s by rw [← this] exact ((hG _ hs).amalgamate _ (G.family_of_elements_compatible s)).2 apply (h _ hs).isSeparatedFor.ext intro V i hi exact (congr_arg Subtype.val ((hG _ hs).valid_glue (G.family_of_elements_compatible s) _ hi) :) theorem Subpresheaf.sheafify_isSheaf (hF : Presieve.IsSheaf J F) : Presieve.IsSheaf J (G.sheafify J).toPresheaf := by refine (isSeparated _ hF.isSeparated).isSheaf fun U S hS x hx ↦ ?_ let S' := Sieve.bind S fun Y f hf => G.sieveOfSection (x f hf).1 have := fun (V) (i : V ⟶ U) (hi : S' i) => hi choose W i₁ i₂ hi₂ h₁ h₂ using this dsimp [-Sieve.bind_apply] at * let x'' : Presieve.FamilyOfElements F S' := fun V i hi => F.map (i₁ V i hi).op (x _ (hi₂ V i hi)) have H : ∀ s, x''.IsAmalgamation s.1 → x.IsAmalgamation s := by intro s H V i hi refine Subtype.ext ?_ apply (hF _ (x i hi).2).isSeparatedFor.ext intro V' i' hi' have hi'' : S' (i' ≫ i) := ⟨_, _, _, hi, hi', rfl⟩ have := H _ hi'' rw [op_comp, F.map_comp] at this exact this.trans (congr_arg Subtype.val (hx _ _ (hi₂ _ _ hi'') hi (h₂ _ _ hi''))) have : x''.Compatible := by intro V₁ V₂ V₃ g₁ g₂ g₃ g₄ S₁ S₂ e rw [← FunctorToTypes.map_comp_apply, ← FunctorToTypes.map_comp_apply] exact congr_arg Subtype.val (hx (g₁ ≫ i₁ _ _ S₁) (g₂ ≫ i₁ _ _ S₂) (hi₂ _ _ S₁) (hi₂ _ _ S₂) (by simp only [Category.assoc, h₂, e])) obtain ⟨t, ht, ht'⟩ := hF _ (J.bind_covering hS fun V i hi => (x i hi).2) _ this refine ⟨⟨t, _⟩, H ⟨t, ?_⟩ ht⟩ refine J.superset_covering ?_ (J.bind_covering hS fun V i hi => (x i hi).2) intro V i hi dsimp rw [ht _ hi] exact h₁ _ _ hi theorem Subpresheaf.eq_sheafify_iff (h : Presieve.IsSheaf J F) : G = G.sheafify J ↔ Presieve.IsSheaf J G.toPresheaf := ⟨fun e => e.symm ▸ G.sheafify_isSheaf h, G.eq_sheafify h⟩ theorem Subpresheaf.isSheaf_iff (h : Presieve.IsSheaf J F) : Presieve.IsSheaf J G.toPresheaf ↔ ∀ (U) (s : F.obj U), G.sieveOfSection s ∈ J (unop U) → s ∈ G.obj U := by rw [← G.eq_sheafify_iff h] change _ ↔ G.sheafify J ≤ G exact ⟨Eq.ge, (G.le_sheafify J).antisymm⟩ theorem Subpresheaf.sheafify_sheafify (h : Presieve.IsSheaf J F) : (G.sheafify J).sheafify J = G.sheafify J := ((Subpresheaf.eq_sheafify_iff _ h).mpr <| G.sheafify_isSheaf h).symm /-- The lift of a presheaf morphism onto the sheafification subpresheaf. -/ noncomputable def Subpresheaf.sheafifyLift (f : G.toPresheaf ⟶ F') (h : Presieve.IsSheaf J F') : (G.sheafify J).toPresheaf ⟶ F' where app _ s := (h (G.sieveOfSection s.1) s.prop).amalgamate (_) ((G.family_of_elements_compatible s.1).map f) naturality := by intro U V i ext s apply (h _ ((Subpresheaf.sheafify J G).toPresheaf.map i s).prop).isSeparatedFor.ext intro W j hj refine (Presieve.IsSheafFor.valid_glue (h _ ((G.sheafify J).toPresheaf.map i s).2) ((G.family_of_elements_compatible _).map _) _ hj).trans ?_ dsimp conv_rhs => rw [← FunctorToTypes.map_comp_apply] change _ = F'.map (j ≫ i.unop).op _ refine Eq.trans ?_ (Presieve.IsSheafFor.valid_glue (h _ s.2) ((G.family_of_elements_compatible s.1).map f) (j ≫ i.unop) ?_).symm · dsimp [Presieve.FamilyOfElements.map] exact congr_arg _ (Subtype.ext (FunctorToTypes.map_comp_apply _ _ _ _).symm) · dsimp [Presieve.FamilyOfElements.map] at hj ⊢ rwa [FunctorToTypes.map_comp_apply] theorem Subpresheaf.to_sheafifyLift (f : G.toPresheaf ⟶ F') (h : Presieve.IsSheaf J F') : Subpresheaf.homOfLe (G.le_sheafify J) ≫ G.sheafifyLift f h = f := by ext U s apply (h _ ((Subpresheaf.homOfLe (G.le_sheafify J)).app U s).prop).isSeparatedFor.ext intro V i hi have := elementwise_of% f.naturality exact (Presieve.IsSheafFor.valid_glue (h _ ((homOfLe (_ : _ ≤ sheafify _ _)).app _ _).2) ((G.family_of_elements_compatible _).map _) _ _).trans (this _ _) theorem Subpresheaf.to_sheafify_lift_unique (h : Presieve.IsSheaf J F') (l₁ l₂ : (G.sheafify J).toPresheaf ⟶ F') (e : Subpresheaf.homOfLe (G.le_sheafify J) ≫ l₁ = Subpresheaf.homOfLe (G.le_sheafify J) ≫ l₂) : l₁ = l₂ := by ext U ⟨s, hs⟩ apply (h _ hs).isSeparatedFor.ext rintro V i hi dsimp at hi rw [← FunctorToTypes.naturality, ← FunctorToTypes.naturality] exact (congr_fun (congr_app e <| op V) ⟨_, hi⟩ :) theorem Subpresheaf.sheafify_le (h : G ≤ G') (hF : Presieve.IsSheaf J F) (hG' : Presieve.IsSheaf J G'.toPresheaf) : G.sheafify J ≤ G' := by intro U x hx convert ((G.sheafifyLift (Subpresheaf.homOfLe h) hG').app U ⟨x, hx⟩).2 apply (hF _ hx).isSeparatedFor.ext intro V i hi have := congr_arg (fun f : G.toPresheaf ⟶ G'.toPresheaf => (NatTrans.app f (op V) ⟨_, hi⟩).1) (G.to_sheafifyLift (Subpresheaf.homOfLe h) hG') convert this.symm rw [← Subpresheaf.nat_trans_naturality] rfl section Image variable (J) in /-- A morphism factors through the sheafification of the image presheaf. -/ @[simps!] def Subpresheaf.toRangeSheafify (f : F' ⟶ F) : F' ⟶ ((Subpresheaf.range f).sheafify J).toPresheaf := toRange f ≫ Subpresheaf.homOfLe ((range f).le_sheafify J) /-- The image sheaf of a morphism between sheaves, defined to be the sheafification of `image_presheaf`. -/ @[simps] def Sheaf.image {F F' : Sheaf J (Type w)} (f : F ⟶ F') : Sheaf J (Type w) := ⟨((Subpresheaf.range f.1).sheafify J).toPresheaf, by rw [isSheaf_iff_isSheaf_of_type] apply Subpresheaf.sheafify_isSheaf rw [← isSheaf_iff_isSheaf_of_type] exact F'.2⟩ /-- A morphism factors through the image sheaf. -/ @[simps] def Sheaf.toImage {F F' : Sheaf J (Type w)} (f : F ⟶ F') : F ⟶ Sheaf.image f := ⟨Subpresheaf.toRangeSheafify J f.1⟩ /-- The inclusion of the image sheaf to the target. -/ @[simps] def Sheaf.imageι {F F' : Sheaf J (Type w)} (f : F ⟶ F') : Sheaf.image f ⟶ F' := ⟨Subpresheaf.ι _⟩ @[reassoc (attr := simp)] theorem Sheaf.toImage_ι {F F' : Sheaf J (Type w)} (f : F ⟶ F') : toImage f ≫ imageι f = f := by ext1 simp [Subpresheaf.toRangeSheafify] instance {F F' : Sheaf J (Type w)} (f : F ⟶ F') : Mono (Sheaf.imageι f) := (sheafToPresheaf J _).mono_of_mono_map (by dsimp infer_instance) instance {F F' : Sheaf J (Type w)} (f : F ⟶ F') : Epi (Sheaf.toImage f) := by refine ⟨@fun G' g₁ g₂ e => ?_⟩ ext U ⟨s, hx⟩ apply ((isSheaf_iff_isSheaf_of_type J _).mp G'.2 _ hx).isSeparatedFor.ext rintro V i ⟨y, e'⟩ change (g₁.val.app _ ≫ G'.val.map _) _ = (g₂.val.app _ ≫ G'.val.map _) _ rw [← NatTrans.naturality, ← NatTrans.naturality] have E : (Sheaf.toImage f).val.app (op V) y = (Sheaf.image f).val.map i.op ⟨s, hx⟩ := Subtype.ext e' have := congr_arg (fun f : F ⟶ G' => (Sheaf.Hom.val f).app _ y) e dsimp at this ⊢ convert this <;> exact E.symm /-- The mono factorization given by `image_sheaf` for a morphism. -/ def imageMonoFactorization {F F' : Sheaf J (Type w)} (f : F ⟶ F') : Limits.MonoFactorisation f where I := Sheaf.image f m := Sheaf.imageι f e := Sheaf.toImage f attribute [local instance] Types.instFunLike Types.instConcreteCategory in /-- The mono factorization given by `image_sheaf` for a morphism is an image. -/ noncomputable def imageFactorization {F F' : Sheaf J (Type (max v u))} (f : F ⟶ F') : Limits.ImageFactorisation f where F := imageMonoFactorization f isImage := { lift := fun I => by haveI M := (Sheaf.Hom.mono_iff_presheaf_mono J (Type (max v u)) _).mp I.m_mono refine ⟨Subpresheaf.homOfLe ?_ ≫ inv (Subpresheaf.toRange I.m.1)⟩ apply Subpresheaf.sheafify_le · conv_lhs => rw [← I.fac] apply Subpresheaf.range_comp_le · rw [← isSheaf_iff_isSheaf_of_type] exact F'.2 · apply Presieve.isSheaf_iso J (asIso <| Subpresheaf.toRange I.m.1) rw [← isSheaf_iff_isSheaf_of_type] exact I.I.2 lift_fac := fun I => by ext1 dsimp [imageMonoFactorization] generalize_proofs h rw [← Subpresheaf.homOfLe_ι h, Category.assoc] congr 1 rw [IsIso.inv_comp_eq, Subpresheaf.toRange_ι] } instance : Limits.HasImages (Sheaf J (Type max v u)) := ⟨fun f => ⟨⟨imageFactorization f⟩⟩⟩ end Image end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/LocallyBijective.lean
import Mathlib.CategoryTheory.Sites.LocallySurjective import Mathlib.CategoryTheory.Sites.Localization /-! # Locally bijective morphisms of presheaves Let `C` be a category equipped with a Grothendieck topology `J`. Let `A` be a concrete category. In this file, we introduce a type class `J.WEqualsLocallyBijective A` which says that the class `J.W` (of morphisms of presheaves which become isomorphisms after sheafification) is the class of morphisms that are both locally injective and locally surjective (i.e. locally bijective). We prove that this holds iff for any presheaf `P : Cᵒᵖ ⥤ A`, the sheafification map `toSheafify J P` is locally bijective. We show that this holds under certain universe assumptions. -/ universe w' w v' v u' u namespace CategoryTheory variable {C : Type u} [Category.{v} C] {J : GrothendieckTopology C} variable {A : Type u'} [Category.{v'} A] {FA : A → A → Type*} {CA : A → Type w'} variable [∀ X Y, FunLike (FA X Y) (CA X) (CA Y)] [ConcreteCategory.{w'} A FA] namespace Sheaf section variable {F G : Sheaf J (Type w)} (f : F ⟶ G) attribute [local instance] Types.instFunLike Types.instConcreteCategory in /-- A morphism of sheaves of types is locally bijective iff it is an isomorphism. (This is generalized below as `isLocallyBijective_iff_isIso`.) -/ private lemma isLocallyBijective_iff_isIso' : IsLocallyInjective f ∧ IsLocallySurjective f ↔ IsIso f := by constructor · rintro ⟨h₁, _⟩ rw [isLocallyInjective_iff_injective] at h₁ suffices ∀ (X : Cᵒᵖ), Function.Surjective (f.val.app X) by rw [← isIso_iff_of_reflects_iso _ (sheafToPresheaf _ _), NatTrans.isIso_iff_isIso_app] intro X rw [isIso_iff_bijective] exact ⟨h₁ X, this X⟩ intro X s have H := (isSheaf_iff_isSheaf_of_type J F.val).1 F.cond _ (Presheaf.imageSieve_mem J f.val s) let t : Presieve.FamilyOfElements F.val (Presheaf.imageSieve f.val s).arrows := fun Y g hg => Presheaf.localPreimage f.val s g hg have ht : t.Compatible := by intro Y₁ Y₂ W g₁ g₂ f₁ f₂ hf₁ hf₂ w apply h₁ have eq₁ := FunctorToTypes.naturality _ _ f.val g₁.op (t f₁ hf₁) have eq₂ := FunctorToTypes.naturality _ _ f.val g₂.op (t f₂ hf₂) have eq₃ := congr_arg (G.val.map g₁.op) (Presheaf.app_localPreimage f.val s _ hf₁) have eq₄ := congr_arg (G.val.map g₂.op) (Presheaf.app_localPreimage f.val s _ hf₂) refine eq₁.trans (eq₃.trans (Eq.trans ?_ (eq₄.symm.trans eq₂.symm))) erw [← FunctorToTypes.map_comp_apply, ← FunctorToTypes.map_comp_apply] simp only [← op_comp, w] refine ⟨H.amalgamate t ht, ?_⟩ · apply (((isSheaf_iff_isSheaf_of_type J G.val).1 G.cond).isSeparated _ (Presheaf.imageSieve_mem J f.val s)).ext intro Y g hg rw [← FunctorToTypes.naturality, H.valid_glue ht] exact Presheaf.app_localPreimage f.val s g hg · intro constructor <;> infer_instance end section variable {F G : Sheaf J A} (f : F ⟶ G) [(forget A).ReflectsIsomorphisms] [J.HasSheafCompose (forget A)] lemma isLocallyBijective_iff_isIso : IsLocallyInjective f ∧ IsLocallySurjective f ↔ IsIso f := by constructor · rintro ⟨_, _⟩ rw [← isIso_iff_of_reflects_iso f (sheafCompose J (forget A)), ← isLocallyBijective_iff_isIso'] constructor <;> infer_instance · intro constructor <;> infer_instance end end Sheaf variable (J A) namespace GrothendieckTopology /-- Given a category `C` equipped with a Grothendieck topology `J` and a concrete category `A`, this property holds if a morphism in `Cᵒᵖ ⥤ A` satisfies `J.W` (i.e. becomes an iso after sheafification) iff it is both locally injective and locally surjective. -/ class WEqualsLocallyBijective : Prop where iff {X Y : Cᵒᵖ ⥤ A} (f : X ⟶ Y) : J.W f ↔ Presheaf.IsLocallyInjective J f ∧ Presheaf.IsLocallySurjective J f section variable {A} variable [J.WEqualsLocallyBijective A] {X Y : Cᵒᵖ ⥤ A} (f : X ⟶ Y) lemma W_iff_isLocallyBijective : J.W f ↔ Presheaf.IsLocallyInjective J f ∧ Presheaf.IsLocallySurjective J f := by apply WEqualsLocallyBijective.iff lemma W_of_isLocallyBijective [Presheaf.IsLocallyInjective J f] [Presheaf.IsLocallySurjective J f] : J.W f := by rw [W_iff_isLocallyBijective] constructor <;> infer_instance variable {J f} lemma W.isLocallyInjective (hf : J.W f) : Presheaf.IsLocallyInjective J f := ((J.W_iff_isLocallyBijective f).1 hf).1 lemma W.isLocallySurjective (hf : J.W f) : Presheaf.IsLocallySurjective J f := ((J.W_iff_isLocallyBijective f).1 hf).2 variable [HasWeakSheafify J A] (P : Cᵒᵖ ⥤ A) instance : Presheaf.IsLocallyInjective J (CategoryTheory.toSheafify J P) := (J.W_toSheafify P).isLocallyInjective instance : Presheaf.IsLocallySurjective J (CategoryTheory.toSheafify J P) := (J.W_toSheafify P).isLocallySurjective end lemma WEqualsLocallyBijective.mk' [HasWeakSheafify J A] [(forget A).ReflectsIsomorphisms] [J.HasSheafCompose (forget A)] [∀ (P : Cᵒᵖ ⥤ A), Presheaf.IsLocallyInjective J (CategoryTheory.toSheafify J P)] [∀ (P : Cᵒᵖ ⥤ A), Presheaf.IsLocallySurjective J (CategoryTheory.toSheafify J P)] : J.WEqualsLocallyBijective A where iff {P Q} f := by rw [W_iff, ← Sheaf.isLocallyBijective_iff_isIso (A := A), ← Presheaf.isLocallyInjective_comp_iff J f (CategoryTheory.toSheafify J Q), ← Presheaf.isLocallySurjective_comp_iff J f (CategoryTheory.toSheafify J Q), CategoryTheory.toSheafify_naturality, Presheaf.comp_isLocallyInjective_iff, Presheaf.comp_isLocallySurjective_iff] instance {D : Type w} [Category.{w'} D] {FD : D → D → Type*} {CD : D → Type (max u v)} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{max u v} D FD] [HasWeakSheafify J D] [J.HasSheafCompose (forget D)] [J.PreservesSheafification (forget D)] [(forget D).ReflectsIsomorphisms] : J.WEqualsLocallyBijective D := by apply WEqualsLocallyBijective.mk' attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance : J.WEqualsLocallyBijective (Type (max u v)) := inferInstance end GrothendieckTopology namespace Presheaf variable {A} variable [HasWeakSheafify J A] [J.WEqualsLocallyBijective A] {P Q : Cᵒᵖ ⥤ A} (φ : P ⟶ Q) lemma isLocallyInjective_presheafToSheaf_map_iff : Sheaf.IsLocallyInjective ((presheafToSheaf J A).map φ) ↔ IsLocallyInjective J φ := by rw [← Sheaf.isLocallyInjective_sheafToPresheaf_map_iff, ← isLocallyInjective_comp_iff J _ (toSheafify J Q), ← comp_isLocallyInjective_iff J (toSheafify J P), toSheafify_naturality, sheafToPresheaf_map] lemma isLocallySurjective_presheafToSheaf_map_iff : Sheaf.IsLocallySurjective ((presheafToSheaf J A).map φ) ↔ IsLocallySurjective J φ := by rw [← Sheaf.isLocallySurjective_sheafToPresheaf_map_iff, ← isLocallySurjective_comp_iff J _ (toSheafify J Q), ← comp_isLocallySurjective_iff J (toSheafify J P), toSheafify_naturality, sheafToPresheaf_map] end Presheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coverage.lean
import Mathlib.CategoryTheory.Sites.Precoverage import Mathlib.CategoryTheory.Sites.Sheaf /-! # Coverages A coverage `K` on a category `C` is a set of presieves associated to every object `X : C`, called "covering presieves". This collection must satisfy a certain "pullback compatibility" condition, saying that whenever `S` is a covering presieve on `X` and `f : Y ⟶ X` is a morphism, then there exists some covering sieve `T` on `Y` such that `T` factors through `S` along `f`. The main difference between a coverage and a Grothendieck pretopology is that we *do not* require `C` to have pullbacks. This is useful, for example, when we want to consider the Grothendieck topology on the category of extremally disconnected sets in the context of condensed mathematics. A more concrete example: If `ℬ` is a basis for a topology on a type `X` (in the sense of `TopologicalSpace.IsTopologicalBasis`) then it naturally induces a coverage on `Opens X` whose associated Grothendieck topology is the one induced by the topology on `X` generated by `ℬ`. (Project: Formalize this!) ## Main Definitions and Results: All definitions are in the `CategoryTheory` namespace. - `Coverage C`: The type of coverages on `C`. - `GrothendieckTopology.toCoverage C`: A function which associates a coverage to any Grothendieck topology. - `Coverage.toGrothendieck C`: A function which associates a Grothendieck topology to any coverage. - `Coverage.gi`: The two functions above form a Galois insertion. - `Presieve.isSheaf_coverage`: Given `K : Coverage C` with associated Grothendieck topology `J`, a `Type*`-valued presheaf on `C` is a sheaf for `K` if and only if it is a sheaf for `J`. ## References We don't follow any particular reference, but the arguments can probably be distilled from the following sources: - [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.1. - [nLab, *Coverage*](https://ncatlab.org/nlab/show/coverage) -/ namespace CategoryTheory universe w w' variable {C D : Type _} [Category C] [Category D] open Limits namespace Presieve /-- Given a morphism `f : Y ⟶ X`, a presieve `S` on `Y` and presieve `T` on `X`, we say that *`S` factors through `T` along `f`*, written `S.FactorsThruAlong T f`, provided that for any morphism `g : Z ⟶ Y` in `S`, there exists some morphism `e : W ⟶ X` in `T` and some morphism `i : Z ⟶ W` such that the obvious square commutes: `i ≫ e = g ≫ f`. This is used in the definition of a coverage. -/ def FactorsThruAlong {X Y : C} (S : Presieve Y) (T : Presieve X) (f : Y ⟶ X) : Prop := ∀ ⦃Z : C⦄ ⦃g : Z ⟶ Y⦄, S g → ∃ (W : C) (i : Z ⟶ W) (e : W ⟶ X), T e ∧ i ≫ e = g ≫ f lemma FactorsThruAlong.pullbackArrows {X Y : C} (f : X ⟶ Y) (R : Presieve Y) [R.HasPullbacks f] : (Presieve.pullbackArrows f R).FactorsThruAlong R f := by intro Z g ⟨W, b, hb⟩ have := R.hasPullback f hb refine ⟨_, pullback.fst _ _, b, hb, pullback.condition⟩ /-- Given `S T : Presieve X`, we say that `S` factors through `T` if any morphism in `S` factors through some morphism in `T`. The lemma `Presieve.isSheafFor_of_factorsThru` gives a *sufficient* condition for a presheaf to be a sheaf for a presieve `T`, in terms of `S.FactorsThru T`, provided that the presheaf is a sheaf for `S`. -/ def FactorsThru {X : C} (S T : Presieve X) : Prop := ∀ ⦃Z : C⦄ ⦃g : Z ⟶ X⦄, S g → ∃ (W : C) (i : Z ⟶ W) (e : W ⟶ X), T e ∧ i ≫ e = g @[simp] lemma factorsThruAlong_id {X : C} (S T : Presieve X) : S.FactorsThruAlong T (𝟙 X) ↔ S.FactorsThru T := by simp [FactorsThruAlong, FactorsThru] lemma factorsThru_of_le {X : C} (S T : Presieve X) (h : S ≤ T) : S.FactorsThru T := fun Y g hg => ⟨Y, 𝟙 _, g, h _ hg, by simp⟩ lemma le_of_factorsThru_sieve {X : C} (S : Presieve X) (T : Sieve X) (h : S.FactorsThru T) : S ≤ T := by rintro Y f hf obtain ⟨W, i, e, h1, rfl⟩ := h hf exact T.downward_closed h1 _ lemma factorsThru_top {X : C} (S : Presieve X) : S.FactorsThru ⊤ := factorsThru_of_le _ _ le_top lemma isSheafFor_of_factorsThru {X : C} {S T : Presieve X} (P : Cᵒᵖ ⥤ Type*) (H : S.FactorsThru T) (hS : S.IsSheafFor P) (h : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, T f → ∃ (R : Presieve Y), R.IsSeparatedFor P ∧ R.FactorsThruAlong S f) : T.IsSheafFor P := by simp only [← Presieve.isSeparatedFor_and_exists_isAmalgamation_iff_isSheafFor] at * choose W i e h1 h2 using H refine ⟨?_, fun x hx => ?_⟩ · intro x y₁ y₂ h₁ h₂ refine hS.1.ext (fun Y g hg => ?_) simp only [← h2 hg, op_comp, P.map_comp, types_comp_apply, h₁ _ (h1 _ ), h₂ _ (h1 _)] let y : S.FamilyOfElements P := fun Y g hg => P.map (i _).op (x (e hg) (h1 _)) have hy : y.Compatible := by intro Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ h rw [← types_comp_apply (P.map (i h₁).op) (P.map g₁.op), ← types_comp_apply (P.map (i h₂).op) (P.map g₂.op), ← P.map_comp, ← op_comp, ← P.map_comp, ← op_comp] apply hx simp only [h2, h, Category.assoc] let ⟨_, h2'⟩ := hS obtain ⟨z, hz⟩ := h2' y hy refine ⟨z, fun Y g hg => ?_⟩ obtain ⟨R, hR1, hR2⟩ := h hg choose WW ii ee hh1 hh2 using hR2 refine hR1.ext (fun Q t ht => ?_) rw [← types_comp_apply (P.map g.op) (P.map t.op), ← P.map_comp, ← op_comp, ← hh2 ht, op_comp, P.map_comp, types_comp_apply, hz _ (hh1 _), ← types_comp_apply _ (P.map (ii ht).op), ← P.map_comp, ← op_comp] apply hx simp only [Category.assoc, h2, hh2] end Presieve variable (C) in /-- The type `Coverage C` of coverages on `C`. A coverage is a collection of *covering* presieves on every object `X : C`, which satisfies a *pullback compatibility* condition. Explicitly, this condition says that whenever `S` is a covering presieve for `X` and `f : Y ⟶ X` is a morphism, then there exists some covering presieve `T` for `Y` such that `T` factors through `S` along `f`. -/ @[ext] structure Coverage extends Precoverage C where /-- Given any covering sieve `S` on `X` and a morphism `f : Y ⟶ X`, there exists some covering sieve `T` on `Y` such that `T` factors through `S` along `f`. -/ pullback : ∀ ⦃X Y : C⦄ (f : Y ⟶ X) (S : Presieve X) (_ : S ∈ coverings X), ∃ (T : Presieve Y), T ∈ coverings Y ∧ T.FactorsThruAlong S f namespace Coverage @[deprecated (since := "2025-08-28")] alias covering := Precoverage.coverings instance : CoeFun (Coverage C) (fun _ => (X : C) → Set (Presieve X)) where coe J := J.coverings end Coverage /-- Associate a coverage to any Grothendieck topology. If `J` is a Grothendieck topology, and `K` is the associated coverage, then a presieve `S` is a covering presieve for `K` if and only if the sieve that it generates is a covering sieve for `J`. -/ def GrothendieckTopology.toCoverage (J : GrothendieckTopology C) : Coverage C where coverings X := { S | Sieve.generate S ∈ J X } pullback := by intro X Y f S (hS : Sieve.generate S ∈ J X) refine ⟨(Sieve.generate S).pullback f, ?_, fun Z g h => h⟩ dsimp rw [Sieve.generate_sieve] exact J.pullback_stable _ hS @[deprecated (since := "2025-09-19")] alias Coverage.ofGrothendieck := GrothendieckTopology.toCoverage lemma GrothendieckTopology.mem_toCoverage_iff {X : C} {S : Presieve X} (J : GrothendieckTopology C) : S ∈ J.toCoverage X ↔ Sieve.generate S ∈ J X := Iff.rfl @[deprecated (since := "2025-09-19")] alias ofGrothendieck_iff := GrothendieckTopology.mem_toCoverage_iff namespace Coverage /-- An auxiliary definition used to define the Grothendieck topology associated to a coverage. See `Coverage.toGrothendieck`. -/ inductive Saturate (K : Coverage C) : (X : C) → Sieve X → Prop where | of (X : C) (S : Presieve X) (hS : S ∈ K X) : Saturate K X (Sieve.generate S) | top (X : C) : Saturate K X ⊤ | transitive (X : C) (R S : Sieve X) : Saturate K X R → (∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, R f → Saturate K Y (S.pullback f)) → Saturate K X S lemma eq_top_pullback {X Y : C} {S T : Sieve X} (h : S ≤ T) (f : Y ⟶ X) (hf : S f) : T.pullback f = ⊤ := by ext Z g simp only [Sieve.pullback_apply, Sieve.top_apply, iff_true] apply h apply S.downward_closed exact hf lemma saturate_of_superset (K : Coverage C) {X : C} {S T : Sieve X} (h : S ≤ T) (hS : Saturate K X S) : Saturate K X T := by apply Saturate.transitive _ _ _ hS intro Y g hg rw [eq_top_pullback (h := h)] · apply Saturate.top · assumption /-- The Grothendieck topology associated to a coverage `K`. It is defined *inductively* as follows: 1. If `S` is a covering presieve for `K`, then the sieve generated by `S` is a covering sieve for the associated Grothendieck topology. 2. The top sieves are in the associated Grothendieck topology. 3. Add all sieves required by the *local character* axiom of a Grothendieck topology. The pullback compatibility condition for a coverage ensures that the associated Grothendieck topology is pullback stable, and so an additional constructor in the inductive construction is not needed. -/ def toGrothendieck (K : Coverage C) : GrothendieckTopology C where sieves := Saturate K top_mem' := .top pullback_stable' := by intro X Y S f hS induction hS generalizing Y with | of X S hS => obtain ⟨R,hR1,hR2⟩ := K.pullback f S hS suffices Sieve.generate R ≤ (Sieve.generate S).pullback f from saturate_of_superset _ this (Saturate.of _ _ hR1) rintro Z g ⟨W, i, e, h1, h2⟩ obtain ⟨WW, ii, ee, hh1, hh2⟩ := hR2 h1 refine ⟨WW, i ≫ ii, ee, hh1, ?_⟩ simp only [hh2, reassoc_of% h2, Category.assoc] | top X => apply Saturate.top | transitive X R S _ hS H1 _ => apply Saturate.transitive · apply H1 f intro Z g hg rw [← Sieve.pullback_comp] exact hS hg transitive' _ _ hS _ hR := .transitive _ _ _ hS hR lemma mem_toGrothendieck {K : Coverage C} {X : C} {S : Sieve X} : S ∈ K.toGrothendieck X ↔ Saturate K X S := .rfl instance : PartialOrder (Coverage C) where le A B := A.coverings ≤ B.coverings le_refl _ _ := le_refl _ le_trans _ _ _ h1 h2 X := le_trans (h1 X) (h2 X) le_antisymm _ _ h1 h2 := Coverage.ext <| funext <| fun X => le_antisymm (h1 X) (h2 X) variable (C) in /-- The two constructions `Coverage.toGrothendieck` and `Coverage.ofGrothendieck` form a Galois insertion. -/ def gi : GaloisInsertion (toGrothendieck (C := C)) (GrothendieckTopology.toCoverage (C := C)) where choice K _ := toGrothendieck K choice_eq := fun _ _ => rfl le_l_u J X S hS := by rw [← Sieve.generate_sieve S] apply Saturate.of dsimp [GrothendieckTopology.toCoverage] rwa [Sieve.generate_sieve S] gc K J := by constructor · intro H X S hS exact H _ <| Saturate.of _ _ hS · intro H X S hS induction hS with | of X S hS => exact H _ hS | top => apply J.top_mem | transitive X R S _ _ H1 H2 => exact J.transitive H1 _ H2 /-- An alternative characterization of the Grothendieck topology associated to a coverage `K`: it is the infimum of all Grothendieck topologies whose associated coverage contains `K`. -/ theorem toGrothendieck_eq_sInf (K : Coverage C) : toGrothendieck K = sInf {J | K ≤ J.toCoverage } := by apply le_antisymm · apply le_sInf intro J hJ X S hS induction hS with | of X S hS => apply hJ; assumption | top => apply J.top_mem | transitive X R S _ _ H1 H2 => exact J.transitive H1 _ H2 · apply sInf_le intro X S hS apply Saturate.of _ _ hS instance : SemilatticeSup (Coverage C) where sup x y := { coverings := fun B ↦ x B ∪ y B pullback := by rintro X Y f S (hx | hy) · obtain ⟨T, hT⟩ := x.pullback f S hx exact ⟨T, Or.inl hT.1, hT.2⟩ · obtain ⟨T, hT⟩ := y.pullback f S hy exact ⟨T, Or.inr hT.1, hT.2⟩ } toPartialOrder := inferInstance le_sup_left _ _ _ := Set.subset_union_left le_sup_right _ _ _ := Set.subset_union_right sup_le _ _ _ hx hy X := Set.union_subset_iff.mpr ⟨hx X, hy X⟩ @[simp] lemma sup_covering (x y : Coverage C) (B : C) : (x ⊔ y) B = x B ∪ y B := rfl /-- Any sieve that contains a covering presieve for a coverage is a covering sieve for the associated Grothendieck topology. -/ theorem mem_toGrothendieck_sieves_of_superset (K : Coverage C) {X : C} {S : Sieve X} {R : Presieve X} (h : R ≤ S) (hR : R ∈ K X) : S ∈ K.toGrothendieck X := K.saturate_of_superset ((Sieve.generate_le_iff _ _).mpr h) (Coverage.Saturate.of X _ hR) end Coverage /-- Any pretopology is a coverage. -/ def Pretopology.toCoverage [HasPullbacks C] (J : Pretopology C) : Coverage C where coverings := J pullback _ _ f R hR := ⟨R.pullbackArrows f, J.pullbacks _ _ hR, .pullbackArrows f R⟩ @[simp] lemma Pretopology.mem_toCoverage [HasPullbacks C] (J : Pretopology C) {X : C} (S : Presieve X) : S ∈ J.toCoverage X ↔ S ∈ J X := .rfl lemma Pretopology.toGrothendieck_toCoverage [HasPullbacks C] (J : Pretopology C) : J.toCoverage.toGrothendieck = J.toGrothendieck := by ext T S rw [mem_toGrothendieck, Coverage.mem_toGrothendieck] refine ⟨fun h ↦ ?_, fun ⟨R, hR, hle⟩ ↦ ?_⟩ · induction h with | of X S hS => use S, hS, Sieve.le_generate S | top X => use Presieve.singleton (𝟙 X), J.has_isos (𝟙 X), le_top | transitive X R S hR hRS hle hfS => obtain ⟨R', hR', hle⟩ := hle choose S' hS' hS'le using hfS refine ⟨Presieve.bind R' (fun Y f hf ↦ S' (hle _ hf)), ?_, fun Z u hu ↦ ?_⟩ · exact J.transitive R' (fun Y f hf ↦ S' (hle Y hf)) hR' fun Y f H ↦ hS' (hle Y H) · obtain ⟨W, g, w, hw, hg, rfl⟩ := hu exact hS'le _ _ hg · refine Coverage.saturate_of_superset _ ?_ (.of _ _ hR) rwa [Sieve.generate_le_iff] namespace Precoverage /-- A precoverage with pullbacks defines a coverage. -/ @[simps toPrecoverage] def toCoverage (J : Precoverage C) [J.HasPullbacks] [J.IsStableUnderBaseChange] : Coverage C where __ := J pullback X Y f S hS := by have : S.HasPullbacks f := J.hasPullbacks_of_mem _ hS exact ⟨S.pullbackArrows f, J.pullbackArrows_mem _ hS, Presieve.FactorsThruAlong.pullbackArrows f S⟩ /-- A precoverage with pullbacks defines a Grothendieck topology. -/ def toGrothendieck (J : Precoverage C) [J.HasPullbacks] [J.IsStableUnderBaseChange] : GrothendieckTopology C := J.toCoverage.toGrothendieck lemma mem_toGrothendieck_iff {J : Precoverage C} [J.HasPullbacks] [J.IsStableUnderBaseChange] {X : C} {S : Sieve X} : S ∈ toGrothendieck J X ↔ J.toCoverage.Saturate X S := .rfl end Precoverage namespace GrothendieckTopology /-- The induced coverage by a Grothendieck topology as a precoverage. -/ def toPrecoverage (J : GrothendieckTopology C) : Precoverage C := J.toCoverage.toPrecoverage lemma mem_toPrecoverage_iff (J : GrothendieckTopology C) {S : C} (R : Presieve S) : R ∈ toPrecoverage J S ↔ Sieve.generate R ∈ J S := .rfl instance (J : GrothendieckTopology C) : (toPrecoverage J).HasIsos where mem_coverings_of_isIso f hf := by simp [mem_toPrecoverage_iff] instance (J : GrothendieckTopology C) : (toPrecoverage J).IsStableUnderComposition where comp_mem_coverings {ι} S X f hf σ Y g hg := by rw [mem_toPrecoverage_iff, ← Presieve.bindOfArrows_ofArrows] exact J.bindOfArrows hf hg instance (J : GrothendieckTopology C) : (toPrecoverage J).IsStableUnderBaseChange where mem_coverings_of_isPullback {ι} S X f hf Y g P p₁ p₂ h := by rw [mem_toPrecoverage_iff, ← Sieve.ofArrows, Sieve.ofArrows_eq_pullback_of_isPullback _ h] exact J.pullback_stable _ hf end GrothendieckTopology /-- `toGrothendieck` and `toPrecoverage` form a Galois connection on the domains where they are defined. -/ lemma Precoverage.toGrothendieck_le_iff_le_toPrecoverage {K : Precoverage C} {J : GrothendieckTopology C} [K.HasPullbacks] [K.IsStableUnderBaseChange] : K.toGrothendieck ≤ J ↔ K ≤ J.toPrecoverage := (Coverage.gi C).gc _ _ open Coverage namespace Presieve /-- The main theorem of this file: Given a coverage `K` on `C`, a `Type*`-valued presheaf on `C` is a sheaf for `K` if and only if it is a sheaf for the associated Grothendieck topology. -/ theorem isSheaf_coverage (K : Coverage C) (P : Cᵒᵖ ⥤ Type*) : Presieve.IsSheaf K.toGrothendieck P ↔ (∀ {X : C} (R : Presieve X), R ∈ K X → Presieve.IsSheafFor P R) := by constructor · intro H X R hR rw [Presieve.isSheafFor_iff_generate] apply H _ <| Saturate.of _ _ hR · intro H X S hS -- This is the key point of the proof: -- We must generalize the induction in the correct way. suffices ∀ ⦃Y : C⦄ (f : Y ⟶ X), Presieve.IsSheafFor P (S.pullback f).arrows by simpa using this (f := 𝟙 _) induction hS with | of X S hS => intro Y f obtain ⟨T, hT1, hT2⟩ := K.pullback f S hS apply Presieve.isSheafFor_of_factorsThru (S := T) · intro Z g hg obtain ⟨W, i, e, h1, h2⟩ := hT2 hg exact ⟨Z, 𝟙 _, g, ⟨W, i, e, h1, h2⟩, by simp⟩ · apply H; assumption · intro Z g _ obtain ⟨R, hR1, hR2⟩ := K.pullback g _ hT1 exact ⟨R, (H _ hR1).isSeparatedFor, hR2⟩ | top => intros; simpa using Presieve.isSheafFor_top_sieve _ | transitive X R S _ _ H1 H2 => intro Y f simp only [← Presieve.isSeparatedFor_and_exists_isAmalgamation_iff_isSheafFor] at * choose H1 H1' using H1 choose H2 H2' using H2 refine ⟨?_, fun x hx => ?_⟩ · intro x t₁ t₂ h₁ h₂ refine (H1 f).ext (fun Z g hg => ?_) refine (H2 hg (𝟙 _)).ext (fun ZZ gg hgg => ?_) simp only [Sieve.pullback_id, Sieve.pullback_apply] at hgg simp only [← types_comp_apply] rw [← P.map_comp, ← op_comp, h₁, h₂] simpa only [Sieve.pullback_apply, Category.assoc] using hgg let y : ∀ ⦃Z : C⦄ (g : Z ⟶ Y), ((S.pullback (g ≫ f)).pullback (𝟙 _)).arrows.FamilyOfElements P := fun Z g ZZ gg hgg => x (gg ≫ g) (by simpa using hgg) have hy : ∀ ⦃Z : C⦄ (g : Z ⟶ Y), (y g).Compatible := by intro Z g Y₁ Y₂ ZZ g₁ g₂ f₁ f₂ h₁ h₂ h rw [hx] rw [reassoc_of% h] choose z hz using fun ⦃Z : C⦄ ⦃g : Z ⟶ Y⦄ (hg : R.pullback f g) => H2' hg (𝟙 _) (y g) (hy g) let q : (R.pullback f).arrows.FamilyOfElements P := fun Z g hg => z hg have hq : q.Compatible := by intro Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ h apply (H2 h₁ g₁).ext intro ZZ gg hgg simp only [← types_comp_apply] rw [← P.map_comp, ← P.map_comp, ← op_comp, ← op_comp, hz, hz] · dsimp [y]; congr 1; simp only [Category.assoc, h] · simpa [reassoc_of% h] using hgg · simpa using hgg obtain ⟨t, ht⟩ := H1' f q hq refine ⟨t, fun Z g hg => ?_⟩ refine (H1 (g ≫ f)).ext (fun ZZ gg hgg => ?_) rw [← types_comp_apply _ (P.map gg.op), ← P.map_comp, ← op_comp, ht] on_goal 2 => simpa using hgg refine (H2 hgg (𝟙 _)).ext (fun ZZZ ggg hggg => ?_) rw [← types_comp_apply _ (P.map ggg.op), ← P.map_comp, ← op_comp, hz] on_goal 2 => simpa using hggg refine (H2 hgg ggg).ext (fun ZZZZ gggg _ => ?_) rw [← types_comp_apply _ (P.map gggg.op), ← P.map_comp, ← op_comp] apply hx simp /-- A presheaf is a sheaf for the Grothendieck topology generated by a union of coverages iff it is a sheaf for the Grothendieck topology generated by each coverage separately. -/ theorem isSheaf_sup (K L : Coverage C) (P : Cᵒᵖ ⥤ Type*) : (Presieve.IsSheaf (K ⊔ L).toGrothendieck) P ↔ (Presieve.IsSheaf K.toGrothendieck) P ∧ (Presieve.IsSheaf L.toGrothendieck) P := by refine ⟨fun h ↦ ⟨Presieve.isSheaf_of_le _ ((gi C).gc.monotone_l le_sup_left) h, Presieve.isSheaf_of_le _ ((gi C).gc.monotone_l le_sup_right) h⟩, fun h ↦ ?_⟩ rw [isSheaf_coverage, isSheaf_coverage] at h rw [isSheaf_coverage] intro X R hR rcases hR with hR | hR · exact h.1 R hR · exact h.2 R hR end Presieve namespace Presheaf theorem isSheaf_iff_isLimit_coverage (K : Coverage C) (P : Cᵒᵖ ⥤ D) : Presheaf.IsSheaf K.toGrothendieck P ↔ ∀ ⦃X : C⦄ (R : Presieve X), R ∈ K X → Nonempty (IsLimit (P.mapCone (Sieve.generate R).arrows.cocone.op)) := by simp only [Presheaf.IsSheaf, Presieve.isSheaf_coverage, isLimit_iff_isSheafFor, ← Presieve.isSheafFor_iff_generate] aesop theorem isSheaf_sup (K L : Coverage C) (P : Cᵒᵖ ⥤ D) : (IsSheaf (K ⊔ L).toGrothendieck) P ↔ (IsSheaf K.toGrothendieck) P ∧ (IsSheaf L.toGrothendieck) P := ⟨fun h ↦ ⟨fun E ↦ ((Presieve.isSheaf_sup K L _).mp (h E)).1, fun E ↦ ((Presieve.isSheaf_sup K L _).mp (h E)).2⟩, fun ⟨h₁, h₂⟩ E ↦ (Presieve.isSheaf_sup K L _).mpr ⟨h₁ E, h₂ E⟩⟩ end Presheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Monoidal.lean
import Mathlib.CategoryTheory.Closed.FunctorCategory.Basic import Mathlib.CategoryTheory.Localization.Monoidal.Braided import Mathlib.CategoryTheory.Sites.Equivalence import Mathlib.CategoryTheory.Sites.SheafHom /-! # Monoidal category structure on categories of sheaves If `A` is a closed braided category with suitable limits, and `J` is a Grothendieck topology with `HasWeakSheafify J A`, then `Sheaf J A` can be equipped with a monoidal category structure. This is not made an instance as in some cases it may conflict with monoidal structure deduced from chosen finite products. ## TODO * show that the monoidal category structure on sheaves is closed, and that the internal hom can be defined in such a way that the underlying presheaf is the internal hom in the category of presheaves. Note that a `MonoidalClosed` instance on sheaves can already be obtained abstractly using the material in `CategoryTheory.Monoidal.Braided.Reflection`. -/ universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] {J : GrothendieckTopology C} {A : Type u₃} [Category.{v₃} A] [MonoidalCategory A] open Opposite Limits MonoidalCategory MonoidalClosed Enriched.FunctorCategory namespace Presheaf variable [MonoidalClosed A] /-- Relation between `functorEnrichedHom` and `presheafHom`. -/ noncomputable def functorEnrichedHomCoyonedaObjEquiv (M : A) (F G : Cᵒᵖ ⥤ A) [HasFunctorEnrichedHom A F G] (X : C) : (functorEnrichedHom A F G ⋙ coyoneda.obj (op M)).obj (op X) ≃ (presheafHom (F ⊗ (Functor.const _).obj M) G).obj (op X) where toFun f := { app j := MonoidalClosed.uncurry (f ≫ enrichedHomπ A _ _ (Under.mk j.unop.hom.op)) naturality j j' φ := by dsimp rw [tensorHom_id, ← uncurry_natural_right, ← uncurry_pre_app, Category.assoc, Category.assoc, ← enrichedOrdinaryCategorySelf_eHomWhiskerRight, ← enrichedOrdinaryCategorySelf_eHomWhiskerLeft] congr 2 exact (enrichedHom_condition A (Under.forget (op X) ⋙ F) (Under.forget (op X) ⋙ G) (i := Under.mk j.unop.hom.op) (j := Under.mk j'.unop.hom.op) (Under.homMk φ.unop.left.op (Quiver.Hom.unop_inj (by simp)))).symm } invFun g := end_.lift (fun j ↦ MonoidalClosed.curry (g.app (op (Over.mk j.hom.unop)))) (fun j j' φ ↦ by dsimp rw [enrichedOrdinaryCategorySelf_eHomWhiskerRight, enrichedOrdinaryCategorySelf_eHomWhiskerLeft, curry_pre_app, ← curry_natural_right] congr 1 let α : Over.mk j'.hom.unop ⟶ Over.mk j.hom.unop := Over.homMk φ.right.unop (Quiver.Hom.op_inj (by simp)) simpa using (g.naturality α.op).symm ) left_inv f := by dsimp ext j dsimp simp only [curry_uncurry, end_.lift_π] rfl right_inv g := by dsimp ext j dsimp simp only [uncurry_curry, end_.lift_π] rfl lemma functorEnrichedHomCoyonedaObjEquiv_naturality {M : A} {F G : Cᵒᵖ ⥤ A} {X Y : C} (f : X ⟶ Y) [HasFunctorEnrichedHom A F G] (y : (functorEnrichedHom A F G ⋙ coyoneda.obj (op M)).obj (op Y)) : functorEnrichedHomCoyonedaObjEquiv M F G X (y ≫ precompEnrichedHom' _ (Under.map f.op) (Iso.refl _) (Iso.refl _)) = (presheafHom (F ⊗ (Functor.const Cᵒᵖ).obj M) G).map f.op (functorEnrichedHomCoyonedaObjEquiv M F G Y y) := by dsimp ext ⟨j⟩ simp [functorEnrichedHomCoyonedaObjEquiv, presheafHom] rfl lemma isSheaf_functorEnrichedHom (F G : Cᵒᵖ ⥤ A) (hG : Presheaf.IsSheaf J G) [HasFunctorEnrichedHom A F G] : Presheaf.IsSheaf J (functorEnrichedHom A F G) := fun M ↦ by rw [Presieve.isSheaf_iff_of_nat_equiv (functorEnrichedHomCoyonedaObjEquiv M F G) (fun _ _ _ _ ↦ functorEnrichedHomCoyonedaObjEquiv_naturality _ _)] rw [← isSheaf_iff_isSheaf_of_type] exact Presheaf.IsSheaf.hom (F ⊗ (Functor.const _).obj M) G hG end Presheaf namespace GrothendieckTopology namespace W variable (J A) in lemma transport_isMonoidal {D : Type u₂} [Category.{v₂} D] (K : GrothendieckTopology D) (G : D ⥤ C) [G.IsCoverDense J] [G.Full] [G.IsContinuous K J] [(G.sheafPushforwardContinuous A K J).EssSurj] [(K.W (A := A)).IsMonoidal] : (J.W (A := A)).IsMonoidal := by rw [← J.W_inverseImage_whiskeringLeft K G] infer_instance variable [MonoidalClosed A] [∀ (F₁ F₂ : Cᵒᵖ ⥤ A), HasFunctorEnrichedHom A F₁ F₂] [∀ (F₁ F₂ : Cᵒᵖ ⥤ A), HasEnrichedHom A F₁ F₂] open MonoidalClosed.FunctorCategory lemma whiskerLeft {G₁ G₂ : Cᵒᵖ ⥤ A} {g : G₁ ⟶ G₂} (hg : J.W g) (F : Cᵒᵖ ⥤ A) : J.W (F ◁ g) := fun H h ↦ by have := hg _ (Presheaf.isSheaf_functorEnrichedHom F H h) rw [← Function.Bijective.of_comp_iff' (f := MonoidalClosed.curry) ((ihom.adjunction _).homEquiv _ _).bijective] rw [← Function.Bijective.of_comp_iff (g := MonoidalClosed.curry) _ ((ihom.adjunction _).homEquiv _ _).bijective] at this convert this using 1 ext α : 1 dsimp rw [curry_natural_left] lemma whiskerRight [BraidedCategory A] {F₁ F₂ : Cᵒᵖ ⥤ A} {f : F₁ ⟶ F₂} (hf : J.W f) (G : Cᵒᵖ ⥤ A) : J.W (f ▷ G) := (J.W.arrow_mk_iso_iff (Arrow.isoMk (β_ F₁ G) (β_ F₂ G))).2 (hf.whiskerLeft G) instance monoidal [BraidedCategory A] : (J.W (A := A)).IsMonoidal where whiskerLeft F _ _ _ hg := hg.whiskerLeft F whiskerRight _ hf G := hf.whiskerRight G end W end GrothendieckTopology namespace Sheaf variable (J A) /-- The monoidal category structure on `Sheaf J A` that is obtained by localization of the monoidal category structure on the category of presheaves. -/ noncomputable def monoidalCategory [(J.W (A := A)).IsMonoidal] [HasWeakSheafify J A] : MonoidalCategory (Sheaf J A) := inferInstanceAs (MonoidalCategory (LocalizedMonoidal (L := presheafToSheaf J A) (W := J.W) (Iso.refl _))) attribute [local instance] monoidalCategory /-- The monoidal category structure on `Sheaf J A` obtained in `Sheaf.monoidalCategory` is braided when `A` is braided. -/ noncomputable def braidedCategory [(J.W (A := A)).IsMonoidal] [HasWeakSheafify J A] [BraidedCategory A] : BraidedCategory (Sheaf J A) := inferInstanceAs (BraidedCategory (LocalizedMonoidal (L := presheafToSheaf J A) (W := J.W) (Iso.refl _))) /-- The monoidal category structure on `Sheaf J A` obtained in `Sheaf.monoidalCategory` is symmetric when `A` is symmetric. -/ noncomputable def symmetricCategory [(J.W (A := A)).IsMonoidal] [HasWeakSheafify J A] [SymmetricCategory A] : SymmetricCategory (Sheaf J A) := inferInstanceAs (SymmetricCategory (LocalizedMonoidal (L := presheafToSheaf J A) (W := J.W) (Iso.refl _))) noncomputable instance [(J.W (A := A)).IsMonoidal] [HasWeakSheafify J A] : (presheafToSheaf J A).Monoidal := inferInstanceAs (Localization.Monoidal.toMonoidalCategory (L := presheafToSheaf J A) (W := J.W) (Iso.refl _)).Monoidal noncomputable instance [(J.W (A := A)).IsMonoidal] [HasWeakSheafify J A] [BraidedCategory A] : letI := braidedCategory J A (presheafToSheaf J A).Braided := inferInstanceAs (Localization.Monoidal.toMonoidalCategory (L := presheafToSheaf J A) (W := J.W) (Iso.refl _)).Braided noncomputable example [HasWeakSheafify J A] [MonoidalClosed A] [BraidedCategory A] [∀ (F₁ F₂ : Cᵒᵖ ⥤ A), HasFunctorEnrichedHom A F₁ F₂] [∀ (F₁ F₂ : Cᵒᵖ ⥤ A), HasEnrichedHom A F₁ F₂] : MonoidalCategory (Sheaf J A) := monoidalCategory J A noncomputable example [HasWeakSheafify J A] [MonoidalClosed A] [BraidedCategory A] [∀ (F₁ F₂ : Cᵒᵖ ⥤ A), HasFunctorEnrichedHom A F₁ F₂] [∀ (F₁ F₂ : Cᵒᵖ ⥤ A), HasEnrichedHom A F₁ F₂] : BraidedCategory (Sheaf J A) := braidedCategory J A noncomputable example [HasWeakSheafify J A] [MonoidalClosed A] [SymmetricCategory A] [∀ (F₁ F₂ : Cᵒᵖ ⥤ A), HasFunctorEnrichedHom A F₁ F₂] [∀ (F₁ F₂ : Cᵒᵖ ⥤ A), HasEnrichedHom A F₁ F₂] : SymmetricCategory (Sheaf J A) := symmetricCategory J A end Sheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/PseudofunctorSheafOver.lean
import Mathlib.CategoryTheory.Bicategory.Functor.LocallyDiscrete import Mathlib.CategoryTheory.Sites.Over /-! # Sheaves on Over categories, as a pseudofunctor Given a Grothendieck topology `J` on a category `C` and a category `A`, we define the pseudofunctor `J.pseudofunctorOver A : Pseudofunctor (LocallyDiscrete Cᵒᵖ) Cat` which sends `X : C` to the category of sheaves on `Over X` with values in `A`. -/ universe v' v u' u namespace CategoryTheory namespace GrothendieckTopology variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) (A : Type u') [Category.{v'} A] /-- Given a Grothendieck topology `J` on a category `C` and a category `A`, this is the pseudofunctor which sends `X : C` to the categories of sheaves on `Over X` with values in `A`. -/ @[simps!] def pseudofunctorOver : Pseudofunctor (LocallyDiscrete Cᵒᵖ) Cat := LocallyDiscrete.mkPseudofunctor (fun X ↦ Cat.of (Sheaf (J.over X.unop) A)) (fun f ↦ J.overMapPullback A f.unop) (fun X ↦ J.overMapPullbackId A X.unop) (fun f g ↦ (J.overMapPullbackComp A g.unop f.unop).symm) (fun f g h ↦ by simpa [overMapPullbackCongr_eq_eqToIso] using J.overMapPullback_assoc A h.unop g.unop f.unop) (fun f ↦ by simpa [overMapPullbackCongr_eq_eqToIso] using J.overMapPullback_comp_id A f.unop) (fun f ↦ by simpa [overMapPullbackCongr_eq_eqToIso] using J.overMapPullback_id_comp A f.unop) end GrothendieckTopology end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Pretopology.lean
import Mathlib.CategoryTheory.Sites.Grothendieck import Mathlib.CategoryTheory.Sites.Precoverage /-! # Grothendieck pretopologies Definition and lemmas about Grothendieck pretopologies. A Grothendieck pretopology for a category `C` is a set of families of morphisms with fixed codomain, satisfying certain closure conditions. We show that a pretopology generates a genuine Grothendieck topology, and every topology has a maximal pretopology which generates it. The pretopology associated to a topological space is defined in `Spaces.lean`. ## Tags coverage, pretopology, site ## References * [nLab, *Grothendieck pretopology*](https://ncatlab.org/nlab/show/Grothendieck+pretopology) * [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92] * [Stacks, *00VG*](https://stacks.math.columbia.edu/tag/00VG) -/ universe v u noncomputable section namespace CategoryTheory open Category Limits Presieve variable {C : Type u} [Category.{v} C] [HasPullbacks C] variable (C) /-- A (Grothendieck) pretopology on `C` consists of a collection of families of morphisms with a fixed target `X` for every object `X` in `C`, called "coverings" of `X`, which satisfies the following three axioms: 1. Every family consisting of a single isomorphism is a covering family. 2. The collection of covering families is stable under pullback. 3. Given a covering family, and a covering family on each domain of the former, the composition is a covering family. In some sense, a pretopology can be seen as Grothendieck topology with weaker saturation conditions, in that each covering is not necessarily downward closed. See: https://ncatlab.org/nlab/show/Grothendieck+pretopology or [MM92] Chapter III, Section 2, Definition 2. -/ @[ext, stacks 00VH "Note that Stacks calls a category together with a pretopology a site, and [MM92] calls this a basis for a topology."] structure Pretopology extends Precoverage C where /-- For all `X : C`, the coverings of `X` (sets of families of morphisms with target `X`) -/ has_isos : ∀ ⦃X Y⦄ (f : Y ⟶ X) [IsIso f], Presieve.singleton f ∈ coverings X pullbacks : ∀ ⦃X Y⦄ (f : Y ⟶ X) (S), S ∈ coverings X → pullbackArrows f S ∈ coverings Y transitive : ∀ ⦃X : C⦄ (S : Presieve X) (Ti : ∀ ⦃Y⦄ (f : Y ⟶ X), S f → Presieve Y), S ∈ coverings X → (∀ ⦃Y⦄ (f) (H : S f), Ti f H ∈ coverings Y) → S.bind Ti ∈ coverings X namespace Pretopology instance : CoeFun (Pretopology C) fun _ => ∀ X : C, Set (Presieve X) := ⟨fun J ↦ J.coverings⟩ variable {C} instance LE : LE (Pretopology C) where le K₁ K₂ := (K₁ : ∀ X : C, Set (Presieve X)) ≤ K₂ theorem le_def {K₁ K₂ : Pretopology C} : K₁ ≤ K₂ ↔ (K₁ : ∀ X : C, Set (Presieve X)) ≤ K₂ := Iff.rfl variable (C) instance : PartialOrder (Pretopology C) := { Pretopology.LE with le_refl := fun _ => le_def.mpr le_rfl le_trans := fun _ _ _ h₁₂ h₂₃ => le_def.mpr (le_trans h₁₂ h₂₃) le_antisymm := fun _ _ h₁₂ h₂₁ => Pretopology.ext (le_antisymm h₁₂ h₂₁) } instance orderTop : OrderTop (Pretopology C) where top := { coverings := fun _ => Set.univ has_isos := fun _ _ _ _ => Set.mem_univ _ pullbacks := fun _ _ _ _ _ => Set.mem_univ _ transitive := fun _ _ _ _ _ => Set.mem_univ _ } le_top _ _ _ _ := Set.mem_univ _ instance : Inhabited (Pretopology C) := ⟨⊤⟩ variable {C} /-- A pretopology `K` can be completed to a Grothendieck topology `J` by declaring a sieve to be `J`-covering if it contains a family in `K`. See also [MM92] Chapter III, Section 2, Equation (2). -/ @[stacks 00ZC] def toGrothendieck (K : Pretopology C) : GrothendieckTopology C where sieves X S := ∃ R ∈ K X, R ≤ (S : Presieve _) top_mem' _ := ⟨Presieve.singleton (𝟙 _), K.has_isos _, fun _ _ _ => ⟨⟩⟩ pullback_stable' X Y S g := by rintro ⟨R, hR, RS⟩ refine ⟨_, K.pullbacks g _ hR, ?_⟩ rw [← Sieve.generate_le_iff, Sieve.pullbackArrows_comm] apply Sieve.pullback_monotone rwa [Sieve.giGenerate.gc] transitive' := by rintro X S ⟨R', hR', RS⟩ R t choose t₁ t₂ t₃ using t refine ⟨_, K.transitive _ _ hR' fun _ f hf => t₂ (RS _ hf), ?_⟩ rintro Y _ ⟨Z, g, f, hg, hf, rfl⟩ apply t₃ (RS _ hg) _ hf theorem mem_toGrothendieck (K : Pretopology C) (X S) : S ∈ toGrothendieck K X ↔ ∃ R ∈ K X, R ≤ (S : Presieve X) := Iff.rfl end Pretopology variable {C} in /-- The largest pretopology generating the given Grothendieck topology. See [MM92] Chapter III, Section 2, Equations (3,4). -/ def GrothendieckTopology.toPretopology (J : GrothendieckTopology C) : Pretopology C where coverings X := {R | Sieve.generate R ∈ J X} has_isos X Y f i := J.covering_of_eq_top (by simp) pullbacks X Y f R hR := by simpa [Sieve.pullbackArrows_comm] using J.pullback_stable f hR transitive X S Ti hS hTi := by apply J.transitive hS intro Y f rintro ⟨Z, g, f, hf, rfl⟩ rw [Sieve.pullback_comp] apply J.pullback_stable g apply J.superset_covering _ (hTi _ hf) rintro Y g ⟨W, h, g, hg, rfl⟩ exact ⟨_, h, _, ⟨_, _, _, hf, hg, rfl⟩, by simp⟩ @[deprecated (since := "2025-09-19")] alias Pretopology.ofGrothendieck := GrothendieckTopology.toPretopology /-- We have a Galois insertion from pretopologies to Grothendieck topologies. -/ def Pretopology.gi : GaloisInsertion (toGrothendieck (C := C)) (GrothendieckTopology.toPretopology (C := C)) where gc K J := by constructor · intro h X R hR exact h _ ⟨_, hR, Sieve.le_generate R⟩ · rintro h X S ⟨R, hR, RS⟩ apply J.superset_covering _ (h _ hR) rwa [Sieve.giGenerate.gc] le_l_u J _ S hS := ⟨S, J.superset_covering (Sieve.le_generate S.arrows) hS, le_rfl⟩ choice x _ := toGrothendieck x choice_eq _ _ := rfl lemma GrothendieckTopology.mem_toPretopology (t : GrothendieckTopology C) {X : C} (S : Presieve X) : S ∈ t.toPretopology X ↔ Sieve.generate S ∈ t X := Iff.rfl @[deprecated (since := "2025-09-19")] alias Pretopology.mem_ofGrothendieck := GrothendieckTopology.mem_toPretopology namespace Pretopology /-- The trivial pretopology, in which the coverings are exactly singleton isomorphisms. This topology is also known as the indiscrete, coarse, or chaotic topology. -/ @[stacks 07GE] def trivial : Pretopology C where coverings X S := ∃ (Y : _) (f : Y ⟶ X) (_ : IsIso f), S = Presieve.singleton f has_isos _ _ _ i := ⟨_, _, i, rfl⟩ pullbacks X Y f S := by rintro ⟨Z, g, i, rfl⟩ refine ⟨pullback g f, pullback.snd _ _, ?_, ?_⟩ · refine ⟨⟨pullback.lift (f ≫ inv g) (𝟙 _) (by simp), ⟨?_, by simp⟩⟩⟩ ext · rw [assoc, pullback.lift_fst, ← pullback.condition_assoc] simp · simp · apply pullback_singleton transitive := by rintro X S Ti ⟨Z, g, i, rfl⟩ hS rcases hS g (singleton_self g) with ⟨Y, f, i, hTi⟩ refine ⟨_, f ≫ g, ?_, ?_⟩ · infer_instance -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): the next four lines were just "ext (W k)" apply funext rintro W apply Set.ext rintro k constructor · rintro ⟨V, h, k, ⟨_⟩, hh, rfl⟩ rw [hTi] at hh cases hh apply singleton.mk · rintro ⟨_⟩ refine bind_comp g singleton.mk ?_ rw [hTi] apply singleton.mk instance orderBot : OrderBot (Pretopology C) where bot := trivial C bot_le K X R := by rintro ⟨Y, f, hf, rfl⟩ exact K.has_isos f /-- The trivial pretopology induces the trivial Grothendieck topology. -/ theorem toGrothendieck_bot : toGrothendieck (C := C) ⊥ = ⊥ := (gi C).gc.l_bot instance : InfSet (Pretopology C) where sInf T := { coverings := sInf ((fun J ↦ J.coverings) '' T) has_isos := fun X Y f _ ↦ by simp only [sInf_apply, Set.iInf_eq_iInter, Set.iInter_coe_set, Set.mem_image, Set.iInter_exists, Set.biInter_and', Set.iInter_iInter_eq_right, Set.mem_iInter] intro t _ exact t.has_isos f pullbacks := fun X Y f S hS ↦ by simp only [sInf_apply, Set.iInf_eq_iInter, Set.iInter_coe_set, Set.mem_image, Set.iInter_exists, Set.biInter_and', Set.iInter_iInter_eq_right, Set.mem_iInter] at hS ⊢ intro t ht exact t.pullbacks f S (hS t ht) transitive := fun X S Ti hS hTi ↦ by simp only [sInf_apply, Set.iInf_eq_iInter, Set.iInter_coe_set, Set.mem_image, Set.iInter_exists, Set.biInter_and', Set.iInter_iInter_eq_right, Set.mem_iInter] at hS hTi ⊢ intro t ht exact t.transitive S Ti (hS t ht) (fun Y f H ↦ hTi f H t ht) } lemma mem_sInf (T : Set (Pretopology C)) {X : C} (S : Presieve X) : S ∈ sInf T X ↔ ∀ t ∈ T, S ∈ t X := by change S ∈ sInf ((fun J : Pretopology C ↦ J.coverings) '' T) X ↔ _ simp lemma sInf_ofGrothendieck (T : Set (GrothendieckTopology C)) : (sInf T).toPretopology = sInf (GrothendieckTopology.toPretopology '' T) := by ext X S simp [mem_sInf, GrothendieckTopology.mem_toPretopology, GrothendieckTopology.mem_sInf] lemma isGLB_sInf (T : Set (Pretopology C)) : IsGLB T (sInf T) := IsGLB.of_image (f := fun J ↦ J.coverings) Iff.rfl (_root_.isGLB_sInf _) /-- The complete lattice structure on pretopologies. This is induced by the `InfSet` instance, but with good definitional equalities for `⊥`, `⊤` and `⊓`. -/ instance : CompleteLattice (Pretopology C) where __ := orderBot C __ := orderTop C inf t₁ t₂ := { coverings := fun X ↦ t₁.coverings X ∩ t₂.coverings X has_isos := fun _ _ f _ ↦ ⟨t₁.has_isos f, t₂.has_isos f⟩ pullbacks := fun _ _ f S hS ↦ ⟨t₁.pullbacks f S hS.left, t₂.pullbacks f S hS.right⟩ transitive := fun _ S Ti hS hTi ↦ ⟨t₁.transitive S Ti hS.left (fun _ f H ↦ (hTi f H).left), t₂.transitive S Ti hS.right (fun _ f H ↦ (hTi f H).right)⟩ } inf_le_left _ _ _ _ hS := hS.left inf_le_right _ _ _ _ hS := hS.right le_inf _ _ _ hts htr X _ hS := ⟨hts X hS, htr X hS⟩ __ := completeLatticeOfInf _ (isGLB_sInf C) lemma mem_inf (t₁ t₂ : Pretopology C) {X : C} (S : Presieve X) : S ∈ (t₁ ⊓ t₂) X ↔ S ∈ t₁ X ∧ S ∈ t₂ X := Iff.rfl end Pretopology /-- If `J` is a precoverage that has isomorphisms and is stable under composition and base change, it defines a pretopology. -/ @[simps toPrecoverage] def Precoverage.toPretopology [Limits.HasPullbacks C] (J : Precoverage C) [J.HasIsos] [J.IsStableUnderBaseChange] [J.IsStableUnderComposition] : Pretopology C where __ := J has_isos X Y f hf := mem_coverings_of_isIso f pullbacks X Y f R hR := J.pullbackArrows_mem f hR transitive X R Ti hR hTi := by obtain ⟨ι, Z, g, rfl⟩ := R.exists_eq_ofArrows choose κ W p hp using fun ⦃Y⦄ (f : Y ⟶ X) hf ↦ (Ti f hf).exists_eq_ofArrows have : (Presieve.ofArrows Z g).bind Ti = .ofArrows (fun ij : Σ i, κ (g i) ⟨i⟩ ↦ W _ _ ij.2) (fun ij ↦ p _ _ ij.2 ≫ g ij.1) := by apply le_antisymm · rintro T u ⟨S, v, w, ⟨i⟩, hv, rfl⟩ rw [hp] at hv obtain ⟨j⟩ := hv exact .mk <| Sigma.mk (β := fun i : ι ↦ κ (g i) ⟨i⟩) i j · rintro T u ⟨ij⟩ use Z ij.1, p (g ij.1) ⟨ij.1⟩ ij.2, g ij.1, ⟨ij.1⟩ rw [hp] exact ⟨⟨_⟩, rfl⟩ rw [this] refine J.comp_mem_coverings (Y := fun (i : ι) (j : κ (g i) ⟨i⟩) ↦ W _ _ j) (g := fun i j ↦ p _ _ j) _ hR fun i ↦ ?_ rw [← hp] exact hTi _ _ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/EqualizerSheafCondition.lean
import Mathlib.CategoryTheory.Limits.Types.Equalizers import Mathlib.CategoryTheory.Limits.Types.Products import Mathlib.CategoryTheory.Sites.IsSheafFor import Mathlib.Tactic.ApplyFun /-! # The equalizer diagram sheaf condition for a presieve In `Mathlib/CategoryTheory/Sites/IsSheafFor.lean` it is defined what it means for a presheaf to be a sheaf *for* a particular presieve. In this file we provide equivalent conditions in terms of equalizer diagrams. * In `Equalizer.Presieve.sheaf_condition`, the sheaf condition at a presieve is shown to be equivalent to that of https://stacks.math.columbia.edu/tag/00VM (and combined with `isSheaf_pretopology`, this shows the notions of `IsSheaf` are exactly equivalent.) * In `Equalizer.Sieve.equalizer_sheaf_condition`, the sheaf condition at a sieve is shown to be equivalent to that of Equation (3) p. 122 in Maclane-Moerdijk [MM92]. ## References * [MM92]: *Sheaves in geometry and logic*, Saunders MacLane, and Ieke Moerdijk: Chapter III, Section 4. * https://stacks.math.columbia.edu/tag/00VL (sheaves on a pretopology or site) -/ universe t w v u namespace CategoryTheory open Opposite CategoryTheory Category Limits Sieve namespace Equalizer variable {C : Type u} [Category.{v} C] (P : Cᵒᵖ ⥤ Type max v u) {X : C} (R : Presieve X) (S : Sieve X) noncomputable section /-- The middle object of the fork diagram given in Equation (3) of [MM92], as well as the fork diagram of the Stacks entry. -/ @[stacks 00VM "This is the middle object of the fork diagram there."] def FirstObj : Type max v u := ∏ᶜ fun f : Σ Y, { f : Y ⟶ X // R f } => P.obj (op f.1) variable {P R} @[ext] lemma FirstObj.ext (z₁ z₂ : FirstObj P R) (h : ∀ (Y : C) (f : Y ⟶ X) (hf : R f), (Pi.π _ ⟨Y, f, hf⟩ : FirstObj P R ⟶ _) z₁ = (Pi.π _ ⟨Y, f, hf⟩ : FirstObj P R ⟶ _) z₂) : z₁ = z₂ := by apply Limits.Types.limit_ext rintro ⟨⟨Y, f, hf⟩⟩ exact h Y f hf variable (P R) /-- Show that `FirstObj` is isomorphic to `FamilyOfElements`. -/ @[simps] def firstObjEqFamily : FirstObj P R ≅ R.FamilyOfElements P where hom t _ _ hf := Pi.π (fun f : Σ Y, { f : Y ⟶ X // R f } => P.obj (op f.1)) ⟨_, _, hf⟩ t inv := Pi.lift fun f x => x _ f.2.2 instance : Inhabited (FirstObj P (⊥ : Presieve X)) := (firstObjEqFamily P _).toEquiv.inhabited instance : Inhabited (FirstObj P ((⊥ : Sieve X) : Presieve X)) := inferInstanceAs <| Inhabited (FirstObj P (⊥ : Presieve X)) /-- The left morphism of the fork diagram given in Equation (3) of [MM92], as well as the fork diagram of the Stacks entry. -/ @[stacks 00VM "This is the left morphism of the fork diagram there."] def forkMap : P.obj (op X) ⟶ FirstObj P R := Pi.lift fun f => P.map f.2.1.op /-! This section establishes the equivalence between the sheaf condition of Equation (3) [MM92] and the definition of `IsSheafFor`. -/ namespace Sieve /-- The rightmost object of the fork diagram of Equation (3) [MM92], which contains the data used to check a family is compatible. -/ def SecondObj : Type max v u := ∏ᶜ fun f : Σ (Y Z : _) (_ : Z ⟶ Y), { f' : Y ⟶ X // S f' } => P.obj (op f.2.1) variable {P S} @[ext] lemma SecondObj.ext (z₁ z₂ : SecondObj P S) (h : ∀ (Y Z : C) (g : Z ⟶ Y) (f : Y ⟶ X) (hf : S.arrows f), (Pi.π _ ⟨Y, Z, g, f, hf⟩ : SecondObj P S ⟶ _) z₁ = (Pi.π _ ⟨Y, Z, g, f, hf⟩ : SecondObj P S ⟶ _) z₂) : z₁ = z₂ := by apply Limits.Types.limit_ext rintro ⟨⟨Y, Z, g, f, hf⟩⟩ apply h variable (P S) /-- The map `p` of Equations (3,4) [MM92]. -/ def firstMap : FirstObj P (S : Presieve X) ⟶ SecondObj P S := Pi.lift fun fg => Pi.π _ (⟨_, _, S.downward_closed fg.2.2.2.2 fg.2.2.1⟩ : Σ Y, { f : Y ⟶ X // S f }) instance : Inhabited (SecondObj P (⊥ : Sieve X)) := ⟨firstMap _ _ default⟩ /-- The map `a` of Equations (3,4) [MM92]. -/ def secondMap : FirstObj P (S : Presieve X) ⟶ SecondObj P S := Pi.lift fun fg => Pi.π _ ⟨_, fg.2.2.2⟩ ≫ P.map fg.2.2.1.op theorem w : forkMap P (S : Presieve X) ≫ firstMap P S = forkMap P S ≫ secondMap P S := by ext simp [firstMap, secondMap, forkMap] /-- The family of elements given by `x : FirstObj P S` is compatible iff `firstMap` and `secondMap` map it to the same point. -/ theorem compatible_iff (x : FirstObj P S.arrows) : ((firstObjEqFamily P S.arrows).hom x).Compatible ↔ firstMap P S x = secondMap P S x := by rw [Presieve.compatible_iff_sieveCompatible] constructor · intro t apply SecondObj.ext intro Y Z g f hf simpa [firstMap, secondMap] using t _ g hf · intro t Y Z f g hf rw [Types.limit_ext_iff'] at t simpa [firstMap, secondMap] using t ⟨⟨Y, Z, g, f, hf⟩⟩ /-- `P` is a sheaf for `S`, iff the fork given by `w` is an equalizer. -/ theorem equalizer_sheaf_condition : Presieve.IsSheafFor P (S : Presieve X) ↔ Nonempty (IsLimit (Fork.ofι _ (w P S))) := by rw [Types.type_equalizer_iff_unique, ← Equiv.forall_congr_right (firstObjEqFamily P (S : Presieve X)).toEquiv.symm] simp_rw [← compatible_iff] simp only [inv_hom_id_apply, Iso.toEquiv_symm_fun] apply forall₂_congr intro x _ apply existsUnique_congr intro t rw [← Iso.toEquiv_symm_fun] rw [Equiv.eq_symm_apply] constructor · intro q funext Y f hf simpa [firstObjEqFamily, forkMap] using q _ _ · intro q Y f hf rw [← q] simp [firstObjEqFamily, forkMap] end Sieve /-! This section establishes the equivalence between the sheaf condition of https://stacks.math.columbia.edu/tag/00VM and the definition of `isSheafFor`. -/ namespace Presieve variable [R.HasPairwisePullbacks] /-- The rightmost object of the fork diagram of the Stacks entry, which contains the data used to check a family of elements for a presieve is compatible. -/ @[simp, stacks 00VM "This is the rightmost object of the fork diagram there."] def SecondObj : Type max v u := ∏ᶜ fun fg : (Σ Y, { f : Y ⟶ X // R f }) × Σ Z, { g : Z ⟶ X // R g } => haveI := Presieve.HasPairwisePullbacks.has_pullbacks fg.1.2.2 fg.2.2.2 P.obj (op (pullback fg.1.2.1 fg.2.2.1)) /-- The map `pr₀*` of the Stacks entry. -/ @[stacks 00VM "This is the map `pr₀*` there."] def firstMap : FirstObj P R ⟶ SecondObj P R := Pi.lift fun fg => haveI := Presieve.HasPairwisePullbacks.has_pullbacks fg.1.2.2 fg.2.2.2 Pi.π _ _ ≫ P.map (pullback.fst _ _).op instance [HasPullbacks C] : Inhabited (SecondObj P (⊥ : Presieve X)) := ⟨firstMap _ _ default⟩ /-- The map `pr₁*` of the Stacks entry. -/ @[stacks 00VM "This is the map `pr₁*` there."] def secondMap : FirstObj P R ⟶ SecondObj P R := Pi.lift fun fg => haveI := Presieve.HasPairwisePullbacks.has_pullbacks fg.1.2.2 fg.2.2.2 Pi.π _ _ ≫ P.map (pullback.snd _ _).op theorem w : forkMap P R ≫ firstMap P R = forkMap P R ≫ secondMap P R := by dsimp ext fg simp only [firstMap, secondMap, forkMap] simp only [limit.lift_π, limit.lift_π_assoc, assoc, Fan.mk_π_app] haveI := Presieve.HasPairwisePullbacks.has_pullbacks fg.1.2.2 fg.2.2.2 rw [← P.map_comp, ← op_comp, pullback.condition] simp /-- The family of elements given by `x : FirstObj P S` is compatible iff `firstMap` and `secondMap` map it to the same point. -/ theorem compatible_iff (x : FirstObj P R) : ((firstObjEqFamily P R).hom x).Compatible ↔ firstMap P R x = secondMap P R x := by rw [Presieve.pullbackCompatible_iff] constructor · intro t apply Limits.Types.limit_ext rintro ⟨⟨Y, f, hf⟩, Z, g, hg⟩ simpa [firstMap, secondMap] using t hf hg · intro t Y Z f g hf hg rw [Types.limit_ext_iff'] at t simpa [firstMap, secondMap] using t ⟨⟨⟨Y, f, hf⟩, Z, g, hg⟩⟩ /-- `P` is a sheaf for `R`, iff the fork given by `w` is an equalizer. -/ @[stacks 00VM] theorem sheaf_condition : R.IsSheafFor P ↔ Nonempty (IsLimit (Fork.ofι _ (w P R))) := by rw [Types.type_equalizer_iff_unique, ← Equiv.forall_congr_right (firstObjEqFamily P R).toEquiv.symm] simp_rw [← compatible_iff, ← Iso.toEquiv_fun, Equiv.apply_symm_apply] apply forall₂_congr intro x _ apply existsUnique_congr intro t rw [Equiv.eq_symm_apply] constructor · intro q funext Y f hf simpa [forkMap] using q _ _ · intro q Y f hf rw [← q] simp [forkMap] namespace Arrows variable (P : Cᵒᵖ ⥤ Type w) {X : C} (R : Presieve X) (S : Sieve X) open Presieve variable {B : C} {I : Type t} [Small.{w} I] (X : I → C) (π : (i : I) → X i ⟶ B) [(Presieve.ofArrows X π).HasPairwisePullbacks] /-- The middle object of the fork diagram of the Stacks entry. The difference between this and `Equalizer.FirstObj P (ofArrows X π)` arises if the family of arrows `π` contains duplicates. The `Presieve.ofArrows` doesn't see those. -/ @[stacks 00VM "The middle object of the fork diagram there."] def FirstObj : Type w := ∏ᶜ (fun i ↦ P.obj (op (X i))) @[ext] lemma FirstObj.ext (z₁ z₂ : FirstObj P X) (h : ∀ i, (Pi.π _ i : FirstObj P X ⟶ _) z₁ = (Pi.π _ i : FirstObj P X ⟶ _) z₂) : z₁ = z₂ := by apply Limits.Types.limit_ext rintro ⟨i⟩ exact h i /-- The rightmost object of the fork diagram of the Stacks entry. The difference between this and `Equalizer.Presieve.SecondObj P (ofArrows X π)` arises if the family of arrows `π` contains duplicates. The `Presieve.ofArrows` doesn't see those. -/ @[stacks 00VM "The rightmost object of the fork diagram there."] def SecondObj : Type w := ∏ᶜ (fun (ij : I × I) ↦ P.obj (op (pullback (π ij.1) (π ij.2)))) @[ext] lemma SecondObj.ext (z₁ z₂ : SecondObj P X π) (h : ∀ ij, (Pi.π _ ij : SecondObj P X π ⟶ _) z₁ = (Pi.π _ ij : SecondObj P X π ⟶ _) z₂) : z₁ = z₂ := by apply Limits.Types.limit_ext rintro ⟨i⟩ exact h i /-- The left morphism of the fork diagram. -/ def forkMap : P.obj (op B) ⟶ FirstObj P X := Pi.lift (fun i ↦ P.map (π i).op) /-- The first of the two parallel morphisms of the fork diagram, induced by the first projection in each pullback. -/ def firstMap : FirstObj P X ⟶ SecondObj P X π := Pi.lift fun _ => Pi.π _ _ ≫ P.map (pullback.fst _ _).op /-- The second of the two parallel morphisms of the fork diagram, induced by the second projection in each pullback. -/ def secondMap : FirstObj P X ⟶ SecondObj P X π := Pi.lift fun _ => Pi.π _ _ ≫ P.map (pullback.snd _ _).op theorem w : forkMap P X π ≫ firstMap P X π = forkMap P X π ≫ secondMap P X π := by ext x ij simp only [firstMap, secondMap, forkMap, types_comp_apply, Types.pi_lift_π_apply, ← FunctorToTypes.map_comp_apply, ← op_comp, pullback.condition] /-- The family of elements given by `x : FirstObj P S` is compatible iff `firstMap` and `secondMap` map it to the same point. See `CategoryTheory.Equalizer.Presieve.Arrows.compatible_iff_of_small` for a version with less universe assumptions. -/ theorem compatible_iff {I : Type w} (X : I → C) (π : (i : I) → X i ⟶ B) [(Presieve.ofArrows X π).HasPairwisePullbacks] (x : FirstObj P X) : (Arrows.Compatible P π ((Types.productIso _).hom x)) ↔ firstMap P X π x = secondMap P X π x := by rw [Arrows.pullbackCompatible_iff] constructor · intro t ext ij simpa [firstMap, secondMap] using t ij.1 ij.2 · intro t i j apply_fun Pi.π (fun (ij : I × I) ↦ P.obj (op (pullback (π ij.1) (π ij.2)))) ⟨i, j⟩ at t simpa [firstMap, secondMap] using t /-- Version of `CategoryTheory.Equalizer.Presieve.Arrows.compatible_iff` for a small indexing type. -/ lemma compatible_iff_of_small (x : FirstObj P X) : (Arrows.Compatible P π ((equivShrink _).symm ((Types.Small.productIso _).hom x))) ↔ firstMap P X π x = secondMap P X π x := by rw [Arrows.pullbackCompatible_iff] refine ⟨fun t ↦ ?_, fun t i j ↦ ?_⟩ · ext ij simpa [firstMap, secondMap] using t ij.1 ij.2 · apply_fun Pi.π (fun (ij : I × I) ↦ P.obj (op (pullback (π ij.1) (π ij.2)))) ⟨i, j⟩ at t simpa [firstMap, secondMap] using t /-- `P` is a sheaf for `Presieve.ofArrows X π`, iff the fork given by `w` is an equalizer. -/ @[stacks 00VM] theorem sheaf_condition : (Presieve.ofArrows X π).IsSheafFor P ↔ Nonempty (IsLimit (Fork.ofι (forkMap P X π) (w P X π))) := by rw [Types.type_equalizer_iff_unique, isSheafFor_arrows_iff] simp only [FirstObj] rw [← Equiv.forall_congr_right ((equivShrink _).trans (Types.Small.productIso _).toEquiv.symm)] simp_rw [← compatible_iff_of_small, ← Iso.toEquiv_fun, Equiv.trans_apply, Equiv.apply_symm_apply, Equiv.symm_apply_apply] apply forall₂_congr intro x _ apply existsUnique_congr intro t rw [Equiv.eq_symm_apply, ← Equiv.symm_apply_eq] constructor · intro q funext i simpa [forkMap] using q i · intro q i rw [← q] simp [forkMap] end Arrows /-- The sheaf condition for a single morphism is the same as the canonical fork diagram being limiting. -/ lemma isSheafFor_singleton_iff {F : Cᵒᵖ ⥤ Type*} {X Y : C} {f : X ⟶ Y} (c : PullbackCone f f) (hc : IsLimit c) : Presieve.IsSheafFor F (.singleton f) ↔ Nonempty (IsLimit (Fork.ofι (F.map f.op) (f := F.map c.fst.op) (g := F.map c.snd.op) (by simp [← Functor.map_comp, ← op_comp, c.condition]))) := by have h (x : F.obj (op X)) : (∀ {Z : C} (p₁ p₂ : Z ⟶ X), p₁ ≫ f = p₂ ≫ f → F.map p₁.op x = F.map p₂.op x) ↔ F.map c.fst.op x = F.map c.snd.op x := by refine ⟨fun H ↦ H _ _ c.condition, fun H Z p₁ p₂ h ↦ ?_⟩ rw [← PullbackCone.IsLimit.lift_fst hc _ _ h, op_comp, FunctorToTypes.map_comp_apply, H] simp [← FunctorToTypes.map_comp_apply, ← op_comp] rw [Types.type_equalizer_iff_unique, Presieve.isSheafFor_singleton] simp_rw [h] /-- Special case of `isSheafFor_singleton_iff` with `c = pullback.cone f f`. -/ lemma isSheafFor_singleton_iff_of_hasPullback {F : Cᵒᵖ ⥤ Type*} {X Y : C} {f : X ⟶ Y} [HasPullback f f] : Presieve.IsSheafFor F (.singleton f) ↔ Nonempty (IsLimit (Fork.ofι (F.map f.op) (f := F.map (pullback.fst f f).op) (g := F.map (pullback.snd f f).op) (by simp [← Functor.map_comp, ← op_comp, pullback.condition]))) := isSheafFor_singleton_iff (pullback.cone f f) (pullback.isLimit f f) end Presieve end end Equalizer end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Abelian.lean
import Mathlib.CategoryTheory.Abelian.FunctorCategory import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Abelian.Transfer import Mathlib.CategoryTheory.Sites.Limits /-! # Category of sheaves is abelian Let `C, D` be categories and `J` be a Grothendieck topology on `C`, when `D` is abelian and sheafification is possible in `C`, `Sheaf J D` is abelian as well (`sheafIsAbelian`). Hence, `presheafToSheaf` is an additive functor (`presheafToSheaf_additive`). -/ noncomputable section namespace CategoryTheory open CategoryTheory.Limits section Abelian universe w' w v u variable {C : Type u} [Category.{v} C] variable {D : Type w} [Category.{w'} D] [Abelian D] variable {J : GrothendieckTopology C} variable [HasSheafify J D] instance sheafIsAbelian : Abelian (Sheaf J D) := let adj := sheafificationAdjunction J D abelianOfAdjunction _ _ (asIso adj.counit) adj attribute [local instance] preservesBinaryBiproducts_of_preservesBinaryProducts instance presheafToSheaf_additive : (presheafToSheaf J D).Additive := (presheafToSheaf J D).additive_of_preservesBinaryBiproducts end Abelian end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/IsSheafFor.lean
import Mathlib.CategoryTheory.Sites.Sieves import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Mono /-! # The sheaf condition for a presieve We define what it means for a presheaf `P : Cᵒᵖ ⥤ Type v` to be a sheaf *for* a particular presieve `R` on `X`: * A *family of elements* `x` for `P` at `R` is an element `x_f` of `P Y` for every `f : Y ⟶ X` in `R`. See `FamilyOfElements`. * The family `x` is *compatible* if, for any `f₁ : Y₁ ⟶ X` and `f₂ : Y₂ ⟶ X` both in `R`, and any `g₁ : Z ⟶ Y₁` and `g₂ : Z ⟶ Y₂` such that `g₁ ≫ f₁ = g₂ ≫ f₂`, the restriction of `x_f₁` along `g₁` agrees with the restriction of `x_f₂` along `g₂`. See `FamilyOfElements.Compatible`. * An *amalgamation* `t` for the family is an element of `P X` such that for every `f : Y ⟶ X` in `R`, the restriction of `t` on `f` is `x_f`. See `FamilyOfElements.IsAmalgamation`. We then say `P` is *separated* for `R` if every compatible family has at most one amalgamation, and it is a *sheaf* for `R` if every compatible family has a unique amalgamation. See `IsSeparatedFor` and `IsSheafFor`. In the special case where `R` is a sieve, the compatibility condition can be simplified: * The family `x` is *compatible* if, for any `f : Y ⟶ X` in `R` and `g : Z ⟶ Y`, the restriction of `x_f` along `g` agrees with `x_(g ≫ f)` (which is well defined since `g ≫ f` is in `R`). See `FamilyOfElements.SieveCompatible` and `compatible_iff_sieveCompatible`. In the special case where `C` has pullbacks, the compatibility condition can be simplified: * The family `x` is *compatible* if, for any `f : Y ⟶ X` and `g : Z ⟶ X` both in `R`, the restriction of `x_f` along `π₁ : pullback f g ⟶ Y` agrees with the restriction of `x_g` along `π₂ : pullback f g ⟶ Z`. See `FamilyOfElements.PullbackCompatible` and `pullbackCompatible_iff`. We also provide equivalent conditions to satisfy alternate definitions given in the literature. * Stacks: The condition of https://stacks.math.columbia.edu/tag/00Z8 is virtually identical to the statement of `isSheafFor_iff_yonedaSheafCondition` (since the bijection described there carries the same information as the unique existence.) * Maclane-Moerdijk [MM92]: Using `compatible_iff_sieveCompatible`, the definitions of `IsSheaf` are equivalent. There are also alternate definitions given: - Yoneda condition: Defined in `yonedaSheafCondition` and equivalence in `isSheafFor_iff_yonedaSheafCondition`. - Matching family for presieves with pullback: `pullbackCompatible_iff`. ## Implementation The sheaf condition is given as a proposition, rather than a subsingleton in `Type (max u₁ v)`. This doesn't seem to make a big difference, other than making a couple of definitions noncomputable, but it means that equivalent conditions can be given as `↔` statements rather than `≃` statements, which can be convenient. ## References * [MM92]: *Sheaves in geometry and logic*, Saunders MacLane, and Ieke Moerdijk: Chapter III, Section 4. * [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.1. * https://stacks.math.columbia.edu/tag/00VL (sheaves on a pretopology or site) * https://stacks.math.columbia.edu/tag/00ZB (sheaves on a topology) -/ universe w w' v₁ v₂ u₁ u₂ namespace CategoryTheory open Opposite CategoryTheory Category Limits Sieve namespace Presieve variable {C : Type u₁} [Category.{v₁} C] variable {P Q U : Cᵒᵖ ⥤ Type w} variable {X Y : C} {S : Sieve X} {R : Presieve X} /-- A family of elements for a presheaf `P` given a collection of arrows `R` with fixed codomain `X` consists of an element of `P Y` for every `f : Y ⟶ X` in `R`. A presheaf is a sheaf (resp, separated) if every *compatible* family of elements has exactly one (resp, at most one) amalgamation. This data is referred to as a `family` in [MM92], Chapter III, Section 4. It is also a concrete version of the elements of the middle object in the Stacks entry which is more useful for direct calculations. It is also used implicitly in Definition C2.1.2 in [Elephant]. -/ @[stacks 00VM "This is a concrete version of the elements of the middle object there."] def FamilyOfElements (P : Cᵒᵖ ⥤ Type w) (R : Presieve X) := ∀ ⦃Y : C⦄ (f : Y ⟶ X), R f → P.obj (op Y) instance : Inhabited (FamilyOfElements P (⊥ : Presieve X)) := ⟨fun _ _ => False.elim⟩ @[ext] lemma FamilyOfElements.ext {R : Presieve X} {x y : R.FamilyOfElements P} (H : ∀ {Y : C} (f : Y ⟶ X) (hf : R f), x f hf = y f hf) : x = y := by funext Z f hf exact H f hf /-- A family of elements for a presheaf on the presieve `R₂` can be restricted to a smaller presieve `R₁`. -/ def FamilyOfElements.restrict {R₁ R₂ : Presieve X} (h : R₁ ≤ R₂) : FamilyOfElements P R₂ → FamilyOfElements P R₁ := fun x _ f hf => x f (h _ hf) /-- The image of a family of elements by a morphism of presheaves. -/ def FamilyOfElements.map (p : FamilyOfElements P R) (φ : P ⟶ Q) : FamilyOfElements Q R := fun _ f hf => φ.app _ (p f hf) @[simp] lemma FamilyOfElements.map_apply (p : FamilyOfElements P R) (φ : P ⟶ Q) {Y : C} (f : Y ⟶ X) (hf : R f) : p.map φ f hf = φ.app _ (p f hf) := rfl lemma FamilyOfElements.restrict_map (p : FamilyOfElements P R) (φ : P ⟶ Q) {R' : Presieve X} (h : R' ≤ R) : (p.restrict h).map φ = (p.map φ).restrict h := rfl variable (P) in /-- A family of elements on `{ f : X ⟶ Y }` is an element of `F(X)`. -/ @[simps apply, simps -isSimp symm_apply] def FamilyOfElements.singletonEquiv {X Y : C} (f : X ⟶ Y) : (singleton f).FamilyOfElements P ≃ P.obj (op X) where toFun x := x f (by simp) invFun x Z g hg := P.map (eqToHom <| by cases hg; rfl).op x left_inv x := by ext _ _ ⟨rfl⟩; simp right_inv x := by simp @[simp] lemma FamilyOfElements.singletonEquiv_symm_apply_self {X Y : C} (f : X ⟶ Y) (x : P.obj (op X)) : (singletonEquiv P f).symm x f ⟨⟩ = x := by simp [singletonEquiv_symm_apply] /-- A family of elements for the arrow set `R` is *compatible* if for any `f₁ : Y₁ ⟶ X` and `f₂ : Y₂ ⟶ X` in `R`, and any `g₁ : Z ⟶ Y₁` and `g₂ : Z ⟶ Y₂`, if the square `g₁ ≫ f₁ = g₂ ≫ f₂` commutes then the elements of `P Z` obtained by restricting the element of `P Y₁` along `g₁` and restricting the element of `P Y₂` along `g₂` are the same. In special cases, this condition can be simplified, see `pullbackCompatible_iff` and `compatible_iff_sieveCompatible`. This is referred to as a "compatible family" in Definition C2.1.2 of [Elephant], and on nlab: https://ncatlab.org/nlab/show/sheaf#GeneralDefinitionInComponents For a more explicit version in the case where `R` is of the form `Presieve.ofArrows`, see `CategoryTheory.Presieve.Arrows.Compatible`. -/ def FamilyOfElements.Compatible (x : FamilyOfElements P R) : Prop := ∀ ⦃Y₁ Y₂ Z⦄ (g₁ : Z ⟶ Y₁) (g₂ : Z ⟶ Y₂) ⦃f₁ : Y₁ ⟶ X⦄ ⦃f₂ : Y₂ ⟶ X⦄ (h₁ : R f₁) (h₂ : R f₂), g₁ ≫ f₁ = g₂ ≫ f₂ → P.map g₁.op (x f₁ h₁) = P.map g₂.op (x f₂ h₂) /-- If the category `C` has pullbacks, this is an alternative condition for a family of elements to be compatible: For any `f : Y ⟶ X` and `g : Z ⟶ X` in the presieve `R`, the restriction of the given elements for `f` and `g` to the pullback agree. This is equivalent to being compatible (provided `C` has pullbacks), shown in `pullbackCompatible_iff`. This is the definition for a "matching" family given in [MM92], Chapter III, Section 4, Equation (5). Viewing the type `FamilyOfElements` as the middle object of the fork in https://stacks.math.columbia.edu/tag/00VM, this condition expresses that `pr₀* (x) = pr₁* (x)`, using the notation defined there. For a more explicit version in the case where `R` is of the form `Presieve.ofArrows`, see `CategoryTheory.Presieve.Arrows.PullbackCompatible`. -/ def FamilyOfElements.PullbackCompatible (x : FamilyOfElements P R) [R.HasPairwisePullbacks] : Prop := ∀ ⦃Y₁ Y₂⦄ ⦃f₁ : Y₁ ⟶ X⦄ ⦃f₂ : Y₂ ⟶ X⦄ (h₁ : R f₁) (h₂ : R f₂), haveI := HasPairwisePullbacks.has_pullbacks h₁ h₂ P.map (pullback.fst f₁ f₂).op (x f₁ h₁) = P.map (pullback.snd f₁ f₂).op (x f₂ h₂) theorem pullbackCompatible_iff (x : FamilyOfElements P R) [R.HasPairwisePullbacks] : x.Compatible ↔ x.PullbackCompatible := by constructor · intro t Y₁ Y₂ f₁ f₂ hf₁ hf₂ apply t haveI := HasPairwisePullbacks.has_pullbacks hf₁ hf₂ apply pullback.condition · intro t Y₁ Y₂ Z g₁ g₂ f₁ f₂ hf₁ hf₂ comm haveI := HasPairwisePullbacks.has_pullbacks hf₁ hf₂ rw [← pullback.lift_fst _ _ comm, op_comp, FunctorToTypes.map_comp_apply, t hf₁ hf₂, ← FunctorToTypes.map_comp_apply, ← op_comp, pullback.lift_snd] /-- The restriction of a compatible family is compatible. -/ theorem FamilyOfElements.Compatible.restrict {R₁ R₂ : Presieve X} (h : R₁ ≤ R₂) {x : FamilyOfElements P R₂} : x.Compatible → (x.restrict h).Compatible := fun q _ _ _ g₁ g₂ _ _ h₁ h₂ comm => q g₁ g₂ (h _ h₁) (h _ h₂) comm /-- Extend a family of elements to the sieve generated by an arrow set. This is the construction described as "easy" in Lemma C2.1.3 of [Elephant]. -/ noncomputable def FamilyOfElements.sieveExtend (x : FamilyOfElements P R) : FamilyOfElements P (generate R : Presieve X) := fun _ _ hf => P.map hf.choose_spec.choose.op (x _ hf.choose_spec.choose_spec.choose_spec.1) /-- The extension of a compatible family to the generated sieve is compatible. -/ theorem FamilyOfElements.Compatible.sieveExtend {x : FamilyOfElements P R} (hx : x.Compatible) : x.sieveExtend.Compatible := by intro _ _ _ _ _ _ _ h₁ h₂ comm iterate 2 erw [← FunctorToTypes.map_comp_apply]; rw [← op_comp] apply hx simp [comm, h₁.choose_spec.choose_spec.choose_spec.2, h₂.choose_spec.choose_spec.choose_spec.2] /-- The extension of a family agrees with the original family. -/ theorem extend_agrees {x : FamilyOfElements P R} (t : x.Compatible) {f : Y ⟶ X} (hf : R f) : x.sieveExtend f (le_generate R Y hf) = x f hf := by have h := (le_generate R Y hf).choose_spec unfold FamilyOfElements.sieveExtend rw [t h.choose (𝟙 _) _ hf _] · simp · rw [id_comp] exact h.choose_spec.choose_spec.2 /-- The restriction of an extension is the original. -/ @[simp] theorem restrict_extend {x : FamilyOfElements P R} (t : x.Compatible) : x.sieveExtend.restrict (le_generate R) = x := by funext Y f hf exact extend_agrees t hf /-- If the arrow set for a family of elements is actually a sieve (i.e. it is downward closed) then the consistency condition can be simplified. This is an equivalent condition, see `compatible_iff_sieveCompatible`. This is the notion of "matching" given for families on sieves given in [MM92], Chapter III, Section 4, Equation 1, and nlab: https://ncatlab.org/nlab/show/matching+family. See also the discussion before Lemma C2.1.4 of [Elephant]. -/ def FamilyOfElements.SieveCompatible (x : FamilyOfElements P (S : Presieve X)) : Prop := ∀ ⦃Y Z⦄ (f : Y ⟶ X) (g : Z ⟶ Y) (hf), x (g ≫ f) (S.downward_closed hf g) = P.map g.op (x f hf) theorem compatible_iff_sieveCompatible (x : FamilyOfElements P (S : Presieve X)) : x.Compatible ↔ x.SieveCompatible := by constructor · intro h Y Z f g hf simpa using h (𝟙 _) g (S.downward_closed hf g) hf (id_comp _) · intro h Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ k simp_rw [← h f₁ g₁ h₁, ← h f₂ g₂ h₂] congr theorem FamilyOfElements.Compatible.to_sieveCompatible {x : FamilyOfElements P (S : Presieve X)} (t : x.Compatible) : x.SieveCompatible := (compatible_iff_sieveCompatible x).1 t /-- Given a family of elements `x` for the sieve `S` generated by a presieve `R`, if `x` is restricted to `R` and then extended back up to `S`, the resulting extension equals `x`. -/ @[simp] theorem extend_restrict {x : FamilyOfElements P (generate R).arrows} (t : x.Compatible) : (x.restrict (le_generate R)).sieveExtend = x := by rw [compatible_iff_sieveCompatible] at t funext _ _ h apply (t _ _ _).symm.trans congr exact h.choose_spec.choose_spec.choose_spec.2 /-- Two compatible families on the sieve generated by a presieve `R` are equal if and only if they are equal when restricted to `R`. -/ theorem restrict_inj {x₁ x₂ : FamilyOfElements P (generate R).arrows} (t₁ : x₁.Compatible) (t₂ : x₂.Compatible) : x₁.restrict (le_generate R) = x₂.restrict (le_generate R) → x₁ = x₂ := fun h => by rw [← extend_restrict t₁, ← extend_restrict t₂] congr /-- Compatible families of elements for a presheaf of types `P` and a presieve `R` are in 1-1 correspondence with compatible families for the same presheaf and the sieve generated by `R`, through extension and restriction. -/ @[simps] noncomputable def compatibleEquivGenerateSieveCompatible : { x : FamilyOfElements P R // x.Compatible } ≃ { x : FamilyOfElements P (generate R : Presieve X) // x.Compatible } where toFun x := ⟨x.1.sieveExtend, x.2.sieveExtend⟩ invFun x := ⟨x.1.restrict (le_generate R), x.2.restrict _⟩ left_inv x := Subtype.ext (restrict_extend x.2) right_inv x := Subtype.ext (extend_restrict x.2) theorem FamilyOfElements.comp_of_compatible (S : Sieve X) {x : FamilyOfElements P S} (t : x.Compatible) {f : Y ⟶ X} (hf : S f) {Z} (g : Z ⟶ Y) : x (g ≫ f) (S.downward_closed hf g) = P.map g.op (x f hf) := by simpa using t (𝟙 _) g (S.downward_closed hf g) hf (id_comp _) lemma FamilyOfElements.compatible_singleton_iff {X Y : C} (f : X ⟶ Y) (x : (singleton f).FamilyOfElements P) : x.Compatible ↔ ∀ {Z : C} (p₁ p₂ : Z ⟶ X), p₁ ≫ f = p₂ ≫ f → P.map p₁.op (x f ⟨⟩) = P.map p₂.op (x f ⟨⟩) := by refine ⟨fun H Z p₁ p₂ h ↦ H _ _ _ _ h, fun H Y₁ Y₂ Z g₁ g₂ f₁ f₂ ↦ ?_⟩ rintro ⟨rfl⟩ ⟨rfl⟩ h exact H _ _ h section FunctorPullback variable {D : Type u₂} [Category.{v₂} D] (F : D ⥤ C) {Z : D} variable {T : Presieve (F.obj Z)} {x : FamilyOfElements P T} /-- Given a family of elements of a sieve `S` on `F(X)`, we can realize it as a family of elements of `S.functorPullback F`. -/ def FamilyOfElements.functorPullback (x : FamilyOfElements P T) : FamilyOfElements (F.op ⋙ P) (T.functorPullback F) := fun _ f hf => x (F.map f) hf theorem FamilyOfElements.Compatible.functorPullback (h : x.Compatible) : (x.functorPullback F).Compatible := by intro Z₁ Z₂ W g₁ g₂ f₁ f₂ h₁ h₂ eq exact h (F.map g₁) (F.map g₂) h₁ h₂ (by simp only [← F.map_comp, eq]) end FunctorPullback /-- Given a family of elements of a sieve `S` on `X` whose values factors through `F`, we can realize it as a family of elements of `S.functorPushforward F`. Since the preimage is obtained by choice, this is not well-defined generally. -/ noncomputable def FamilyOfElements.functorPushforward {D : Type u₂} [Category.{v₂} D] (F : D ⥤ C) {X : D} {T : Presieve X} (x : FamilyOfElements (F.op ⋙ P) T) : FamilyOfElements P (T.functorPushforward F) := fun Y f h => by obtain ⟨Z, g, h, h₁, _⟩ := getFunctorPushforwardStructure h exact P.map h.op (x g h₁) section Pullback /-- Given a family of elements of a sieve `S` on `X`, and a map `Y ⟶ X`, we can obtain a family of elements of `S.pullback f` by taking the same elements. -/ def FamilyOfElements.pullback (f : Y ⟶ X) (x : FamilyOfElements P (S : Presieve X)) : FamilyOfElements P (S.pullback f : Presieve Y) := fun _ g hg => x (g ≫ f) hg theorem FamilyOfElements.Compatible.pullback (f : Y ⟶ X) {x : FamilyOfElements P S.arrows} (h : x.Compatible) : (x.pullback f).Compatible := by simp only [compatible_iff_sieveCompatible] at h ⊢ intro W Z f₁ f₂ hf unfold FamilyOfElements.pullback rw [← h (f₁ ≫ f) f₂ hf] congr 1 simp only [assoc] end Pullback /-- Given a morphism of presheaves `f : P ⟶ Q`, we can take a family of elements valued in `P` to a family of elements valued in `Q` by composing with `f`. -/ @[deprecated map (since := "2025-09-25")] def FamilyOfElements.compPresheafMap (f : P ⟶ Q) (x : FamilyOfElements P R) : FamilyOfElements Q R := fun Y g hg => f.app (op Y) (x g hg) @[simp] lemma FamilyOfElements.map_id (x : FamilyOfElements P R) : x.map (𝟙 _) = x := rfl @[simp] lemma FamilyOfElements.map_comp (x : FamilyOfElements P R) (f : P ⟶ Q) (g : Q ⟶ U) : (x.map f).map g = x.map (f ≫ g) := by rfl theorem FamilyOfElements.Compatible.map (f : P ⟶ Q) {x : FamilyOfElements P R} (h : x.Compatible) : (x.map f).Compatible := by intro Z₁ Z₂ W g₁ g₂ f₁ f₂ h₁ h₂ eq unfold FamilyOfElements.map rwa [← FunctorToTypes.naturality, ← FunctorToTypes.naturality, h] @[deprecated (since := "2025-09-25")] alias FamilyOfElements.compPresheafMap_id := FamilyOfElements.map_id @[deprecated (since := "2025-09-25")] alias FamilyOfElements.compPresheafMap_comp := FamilyOfElements.map_comp @[deprecated (since := "2025-09-25")] alias FamilyOfElements.Compatible.compPresheafMap := FamilyOfElements.Compatible.map /-- The given element `t` of `P.obj (op X)` is an *amalgamation* for the family of elements `x` if every restriction `P.map f.op t = x_f` for every arrow `f` in the presieve `R`. This is the definition given in https://ncatlab.org/nlab/show/sheaf#GeneralDefinitionInComponents, and https://ncatlab.org/nlab/show/matching+family, as well as [MM92], Chapter III, Section 4, equation (2). -/ def FamilyOfElements.IsAmalgamation (x : FamilyOfElements P R) (t : P.obj (op X)) : Prop := ∀ ⦃Y : C⦄ (f : Y ⟶ X) (h : R f), P.map f.op t = x f h theorem FamilyOfElements.IsAmalgamation.map {x : FamilyOfElements P R} {t} (f : P ⟶ Q) (h : x.IsAmalgamation t) : (x.map f).IsAmalgamation (f.app (op X) t) := by intro Y g hg dsimp [FamilyOfElements.map] change (f.app _ ≫ Q.map _) _ = _ rw [← f.naturality, types_comp_apply, h g hg] @[deprecated (since := "2025-09-25")] alias FamilyOfElements.IsAmalgamation.compPresheafMap := FamilyOfElements.IsAmalgamation.map theorem is_compatible_of_exists_amalgamation (x : FamilyOfElements P R) (h : ∃ t, x.IsAmalgamation t) : x.Compatible := by obtain ⟨t, ht⟩ := h intro Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ comm rw [← ht _ h₁, ← ht _ h₂, ← FunctorToTypes.map_comp_apply, ← op_comp, comm] simp theorem isAmalgamation_restrict {R₁ R₂ : Presieve X} (h : R₁ ≤ R₂) (x : FamilyOfElements P R₂) (t : P.obj (op X)) (ht : x.IsAmalgamation t) : (x.restrict h).IsAmalgamation t := fun Y f hf => ht f (h Y hf) theorem isAmalgamation_sieveExtend {R : Presieve X} (x : FamilyOfElements P R) (t : P.obj (op X)) (ht : x.IsAmalgamation t) : x.sieveExtend.IsAmalgamation t := by intro Y f hf dsimp [FamilyOfElements.sieveExtend] rw [← ht _, ← FunctorToTypes.map_comp_apply, ← op_comp, hf.choose_spec.choose_spec.choose_spec.2] @[simp] lemma FamilyOfElements.isAmalgamation_singleton_iff {X Y : C} (f : X ⟶ Y) (x : (singleton f).FamilyOfElements P) (y : P.obj (op Y)) : x.IsAmalgamation y ↔ P.map f.op y = x f ⟨⟩ := by refine ⟨fun H ↦ H _ _, ?_⟩ rintro H Y g ⟨rfl⟩ exact H /-- A presheaf is separated for a presieve if there is at most one amalgamation. -/ def IsSeparatedFor (P : Cᵒᵖ ⥤ Type w) (R : Presieve X) : Prop := ∀ (x : FamilyOfElements P R) (t₁ t₂), x.IsAmalgamation t₁ → x.IsAmalgamation t₂ → t₁ = t₂ theorem IsSeparatedFor.ext {R : Presieve X} (hR : IsSeparatedFor P R) {t₁ t₂ : P.obj (op X)} (h : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄ (_ : R f), P.map f.op t₁ = P.map f.op t₂) : t₁ = t₂ := hR (fun _ f _ => P.map f.op t₂) t₁ t₂ (fun _ _ hf => h hf) fun _ _ _ => rfl theorem isSeparatedFor_iff_generate : IsSeparatedFor P R ↔ IsSeparatedFor P (generate R : Presieve X) := by constructor · intro h x t₁ t₂ ht₁ ht₂ apply h (x.restrict (le_generate R)) t₁ t₂ _ _ · exact isAmalgamation_restrict _ x t₁ ht₁ · exact isAmalgamation_restrict _ x t₂ ht₂ · intro h x t₁ t₂ ht₁ ht₂ apply h x.sieveExtend · exact isAmalgamation_sieveExtend x t₁ ht₁ · exact isAmalgamation_sieveExtend x t₂ ht₂ theorem isSeparatedFor_top (P : Cᵒᵖ ⥤ Type w) : IsSeparatedFor P (⊤ : Presieve X) := fun x t₁ t₂ h₁ h₂ => by have q₁ := h₁ (𝟙 X) (by tauto) have q₂ := h₂ (𝟙 X) (by tauto) simp only [op_id, FunctorToTypes.map_id_apply] at q₁ q₂ rw [q₁, q₂] /-- We define `P` to be a sheaf for the presieve `R` if every compatible family has a unique amalgamation. This is the definition of a sheaf for the given presieve given in C2.1.2 of [Elephant], and https://ncatlab.org/nlab/show/sheaf#GeneralDefinitionInComponents. Using `compatible_iff_sieveCompatible`, this is equivalent to the definition of a sheaf in [MM92], Chapter III, Section 4. -/ def IsSheafFor (P : Cᵒᵖ ⥤ Type w) (R : Presieve X) : Prop := ∀ x : FamilyOfElements P R, x.Compatible → ∃! t, x.IsAmalgamation t /-- This is an equivalent condition to be a sheaf, which is useful for the abstraction to local operators on elementary toposes. However this definition is defined only for sieves, not presieves. The equivalence between this and `IsSheafFor` is given in `isSheafFor_iff_yonedaSheafCondition`. This version is also useful to establish that being a sheaf is preserved under isomorphism of presheaves. See the discussion before Equation (3) of [MM92], Chapter III, Section 4. See also C2.1.4 of [Elephant]. -/ @[stacks 00Z8 "Direct reformulation"] def YonedaSheafCondition (P : Cᵒᵖ ⥤ Type v₁) (S : Sieve X) : Prop := ∀ f : S.functor ⟶ P, ∃! g, S.functorInclusion ≫ g = f -- TODO: We can generalize the universe parameter v₁ above by composing with -- appropriate `ulift_functor`s. /-- (Implementation). This is a (primarily internal) equivalence between natural transformations and compatible families. Cf the discussion after Lemma 7.47.10 in <https://stacks.math.columbia.edu/tag/00YW>. See also the proof of C2.1.4 of [Elephant], and the discussion in [MM92], Chapter III, Section 4. -/ def natTransEquivCompatibleFamily {P : Cᵒᵖ ⥤ Type v₁} : (S.functor ⟶ P) ≃ { x : FamilyOfElements P (S : Presieve X) // x.Compatible } where toFun α := by refine ⟨fun Y f hf => ?_, ?_⟩ · apply α.app (op Y) ⟨_, hf⟩ · rw [compatible_iff_sieveCompatible] intro Y Z f g hf dsimp rw [← FunctorToTypes.naturality _ _ α g.op] rfl invFun t := { app := fun _ f => t.1 _ f.2 naturality := fun Y Z g => by ext ⟨f, hf⟩ apply t.2.to_sieveCompatible _ } left_inv α := by ext X ⟨_, _⟩ rfl right_inv := by rintro ⟨x, hx⟩ rfl /-- (Implementation). A lemma useful to prove `isSheafFor_iff_yonedaSheafCondition`. -/ theorem extension_iff_amalgamation {P : Cᵒᵖ ⥤ Type v₁} (x : S.functor ⟶ P) (g : yoneda.obj X ⟶ P) : S.functorInclusion ≫ g = x ↔ (natTransEquivCompatibleFamily x).1.IsAmalgamation (yonedaEquiv g) := by change _ ↔ ∀ ⦃Y : C⦄ (f : Y ⟶ X) (h : S f), P.map f.op (yonedaEquiv g) = x.app (op Y) ⟨f, h⟩ constructor · rintro rfl Y f hf rw [yonedaEquiv_naturality] simp [yonedaEquiv_apply] · intro h ext Y ⟨f, hf⟩ convert h f hf rw [yonedaEquiv_naturality] simp [yonedaEquiv] /-- The yoneda version of the sheaf condition is equivalent to the sheaf condition. C2.1.4 of [Elephant]. -/ theorem isSheafFor_iff_yonedaSheafCondition {P : Cᵒᵖ ⥤ Type v₁} : IsSheafFor P (S : Presieve X) ↔ YonedaSheafCondition P S := by rw [IsSheafFor, YonedaSheafCondition] simp_rw [extension_iff_amalgamation] rw [Equiv.forall_congr_left natTransEquivCompatibleFamily] rw [Subtype.forall] exact forall₂_congr fun x hx ↦ by simp [Equiv.existsUnique_congr_right] /-- If `P` is a sheaf for the sieve `S` on `X`, a natural transformation from `S` (viewed as a functor) to `P` can be (uniquely) extended to all of `yoneda.obj X`. ``` f S → P ↓ ↗ yX ``` -/ noncomputable def IsSheafFor.extend {P : Cᵒᵖ ⥤ Type v₁} (h : IsSheafFor P (S : Presieve X)) (f : S.functor ⟶ P) : yoneda.obj X ⟶ P := (isSheafFor_iff_yonedaSheafCondition.1 h f).exists.choose /-- Show that the extension of `f : S.functor ⟶ P` to all of `yoneda.obj X` is in fact an extension, i.e. that the triangle below commutes, provided `P` is a sheaf for `S` ``` f S → P ↓ ↗ yX ``` -/ @[reassoc (attr := simp)] theorem IsSheafFor.functorInclusion_comp_extend {P : Cᵒᵖ ⥤ Type v₁} (h : IsSheafFor P S.arrows) (f : S.functor ⟶ P) : S.functorInclusion ≫ h.extend f = f := (isSheafFor_iff_yonedaSheafCondition.1 h f).exists.choose_spec /-- The extension of `f` to `yoneda.obj X` is unique. -/ theorem IsSheafFor.unique_extend {P : Cᵒᵖ ⥤ Type v₁} (h : IsSheafFor P S.arrows) {f : S.functor ⟶ P} (t : yoneda.obj X ⟶ P) (ht : S.functorInclusion ≫ t = f) : t = h.extend f := (isSheafFor_iff_yonedaSheafCondition.1 h f).unique ht (h.functorInclusion_comp_extend f) /-- If `P` is a sheaf for the sieve `S` on `X`, then if two natural transformations from `yoneda.obj X` to `P` agree when restricted to the subfunctor given by `S`, they are equal. -/ theorem IsSheafFor.hom_ext {P : Cᵒᵖ ⥤ Type v₁} (h : IsSheafFor P (S : Presieve X)) (t₁ t₂ : yoneda.obj X ⟶ P) (ht : S.functorInclusion ≫ t₁ = S.functorInclusion ≫ t₂) : t₁ = t₂ := (h.unique_extend t₁ ht).trans (h.unique_extend t₂ rfl).symm /-- `P` is a sheaf for `R` iff it is separated for `R` and there exists an amalgamation. -/ theorem isSeparatedFor_and_exists_isAmalgamation_iff_isSheafFor : (IsSeparatedFor P R ∧ ∀ x : FamilyOfElements P R, x.Compatible → ∃ t, x.IsAmalgamation t) ↔ IsSheafFor P R := by rw [IsSeparatedFor, ← forall_and] apply forall_congr' intro x constructor · intro z hx exact existsUnique_of_exists_of_unique (z.2 hx) z.1 · intro h refine ⟨?_, ExistsUnique.exists ∘ h⟩ intro t₁ t₂ ht₁ ht₂ apply (h _).unique ht₁ ht₂ exact is_compatible_of_exists_amalgamation x ⟨_, ht₂⟩ /-- If `P` is separated for `R` and every family has an amalgamation, then `P` is a sheaf for `R`. -/ theorem IsSeparatedFor.isSheafFor (t : IsSeparatedFor P R) : (∀ x : FamilyOfElements P R, x.Compatible → ∃ t, x.IsAmalgamation t) → IsSheafFor P R := by rw [← isSeparatedFor_and_exists_isAmalgamation_iff_isSheafFor] exact And.intro t /-- If `P` is a sheaf for `R`, it is separated for `R`. -/ theorem IsSheafFor.isSeparatedFor : IsSheafFor P R → IsSeparatedFor P R := fun q => (isSeparatedFor_and_exists_isAmalgamation_iff_isSheafFor.2 q).1 /-- Get the amalgamation of the given compatible family, provided we have a sheaf. -/ noncomputable def IsSheafFor.amalgamate (t : IsSheafFor P R) (x : FamilyOfElements P R) (hx : x.Compatible) : P.obj (op X) := (t x hx).exists.choose theorem IsSheafFor.isAmalgamation (t : IsSheafFor P R) {x : FamilyOfElements P R} (hx : x.Compatible) : x.IsAmalgamation (t.amalgamate x hx) := (t x hx).exists.choose_spec @[simp] theorem IsSheafFor.valid_glue (t : IsSheafFor P R) {x : FamilyOfElements P R} (hx : x.Compatible) (f : Y ⟶ X) (Hf : R f) : P.map f.op (t.amalgamate x hx) = x f Hf := t.isAmalgamation hx f Hf /-- C2.1.3 in [Elephant] -/ theorem isSheafFor_iff_generate (R : Presieve X) : IsSheafFor P R ↔ IsSheafFor P (generate R : Presieve X) := by rw [← isSeparatedFor_and_exists_isAmalgamation_iff_isSheafFor] rw [← isSeparatedFor_and_exists_isAmalgamation_iff_isSheafFor] rw [← isSeparatedFor_iff_generate] apply and_congr (Iff.refl _) constructor · intro q x hx apply Exists.imp _ (q _ (hx.restrict (le_generate R))) intro t ht simpa [hx] using isAmalgamation_sieveExtend _ _ ht · intro q x hx apply Exists.imp _ (q _ hx.sieveExtend) intro t ht simpa [hx] using isAmalgamation_restrict (le_generate R) _ _ ht /-- Every presheaf is a sheaf for the family {𝟙 X}. [Elephant] C2.1.5(i) -/ theorem isSheafFor_singleton_iso (P : Cᵒᵖ ⥤ Type w) : IsSheafFor P (Presieve.singleton (𝟙 X)) := by intro x _ refine ⟨x _ (Presieve.singleton_self _), ?_, ?_⟩ · rintro _ _ ⟨rfl, rfl⟩ simp · intro t ht simpa using ht _ (Presieve.singleton_self _) /-- Every presheaf is a sheaf for the maximal sieve. [Elephant] C2.1.5(ii) -/ theorem isSheafFor_top_sieve (P : Cᵒᵖ ⥤ Type w) : IsSheafFor P ((⊤ : Sieve X) : Presieve X) := by rw [← generate_of_singleton_isSplitEpi (𝟙 X)] rw [← isSheafFor_iff_generate] apply isSheafFor_singleton_iso /-- If `P₁ : Cᵒᵖ ⥤ Type w` and `P₂ : Cᵒᵖ ⥤ Type w` are two naturally equivalent presheaves, and `P₁` is a sheaf for a presieve `R`, then `P₂` is also a sheaf for `R`. -/ lemma isSheafFor_of_nat_equiv {P₁ : Cᵒᵖ ⥤ Type w} {P₂ : Cᵒᵖ ⥤ Type w'} (e : ∀ ⦃X : C⦄, P₁.obj (op X) ≃ P₂.obj (op X)) (he : ∀ ⦃X Y : C⦄ (f : X ⟶ Y) (x : P₁.obj (op Y)), e (P₁.map f.op x) = P₂.map f.op (e x)) {X : C} {R : Presieve X} (hP₁ : IsSheafFor P₁ R) : IsSheafFor P₂ R := fun x₂ hx₂ ↦ by have he' : ∀ ⦃X Y : C⦄ (f : X ⟶ Y) (x : P₂.obj (op Y)), e.symm (P₂.map f.op x) = P₁.map f.op (e.symm x) := fun X Y f x ↦ e.injective (by simp only [Equiv.apply_symm_apply, he]) let x₁ : FamilyOfElements P₁ R := fun Y f hf ↦ e.symm (x₂ f hf) have hx₁ : x₁.Compatible := fun Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ fac ↦ e.injective (by simp only [he, Equiv.apply_symm_apply, hx₂ g₁ g₂ h₁ h₂ fac, x₁]) have : ∀ (t₂ : P₂.obj (op X)), x₂.IsAmalgamation t₂ ↔ x₁.IsAmalgamation (e.symm t₂) := fun t₂ ↦ by simp only [FamilyOfElements.IsAmalgamation, x₁, ← he', EmbeddingLike.apply_eq_iff_eq] refine ⟨e (hP₁.amalgamate x₁ hx₁), ?_, ?_⟩ · dsimp simp only [this, Equiv.symm_apply_apply] exact IsSheafFor.isAmalgamation hP₁ hx₁ · intro t₂ ht₂ refine e.symm.injective ?_ simp only [Equiv.symm_apply_apply] exact hP₁.isSeparatedFor x₁ _ _ (by simpa only [this] using ht₂) (IsSheafFor.isAmalgamation hP₁ hx₁) /-- If `P` is a sheaf for `S`, and it is iso to `P'`, then `P'` is a sheaf for `S`. This shows that "being a sheaf for a presieve" is a mathematical or hygienic property. -/ theorem isSheafFor_iso {P' : Cᵒᵖ ⥤ Type w} (i : P ≅ P') (hP : IsSheafFor P R) : IsSheafFor P' R := isSheafFor_of_nat_equiv (fun X ↦ (i.app (op X)).toEquiv) (fun _ _ f x ↦ congr_fun (i.hom.naturality f.op) x) hP /-- The property of being separated for some presieve is preserved under isomorphisms. -/ theorem isSeparatedFor_iso {P' : Cᵒᵖ ⥤ Type w} (i : P ≅ P') (hP : IsSeparatedFor P R) : IsSeparatedFor P' R := by intro x t₁ t₂ ht₁ ht₂ simpa using congrArg (i.hom.app _) <| hP (x.map i.inv) _ _ (ht₁.map i.inv) (ht₂.map i.inv) /-- If a presieve `R` on `X` has a subsieve `S` such that: * `P` is a sheaf for `S`. * For every `f` in `R`, `P` is separated for the pullback of `S` along `f`, then `P` is a sheaf for `R`. This is closely related to [Elephant] C2.1.6(i). -/ theorem isSheafFor_subsieve_aux (P : Cᵒᵖ ⥤ Type w) {S : Sieve X} {R : Presieve X} (h : (S : Presieve X) ≤ R) (hS : IsSheafFor P (S : Presieve X)) (trans : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, R f → IsSeparatedFor P (S.pullback f : Presieve Y)) : IsSheafFor P R := by rw [← isSeparatedFor_and_exists_isAmalgamation_iff_isSheafFor] constructor · intro x t₁ t₂ ht₁ ht₂ exact hS.isSeparatedFor _ _ _ (isAmalgamation_restrict h x t₁ ht₁) (isAmalgamation_restrict h x t₂ ht₂) · intro x hx use hS.amalgamate _ (hx.restrict h) intro W j hj apply (trans hj).ext intro Y f hf rw [← FunctorToTypes.map_comp_apply, ← op_comp, hS.valid_glue (hx.restrict h) _ hf, FamilyOfElements.restrict, ← hx (𝟙 _) f (h _ hf) _ (id_comp _)] simp /-- If `P` is a sheaf for every pullback of the sieve `S`, then `P` is a sheaf for any presieve which contains `S`. This is closely related to [Elephant] C2.1.6. -/ theorem isSheafFor_subsieve (P : Cᵒᵖ ⥤ Type w) {S : Sieve X} {R : Presieve X} (h : (S : Presieve X) ≤ R) (trans : ∀ ⦃Y⦄ (f : Y ⟶ X), IsSheafFor P (S.pullback f : Presieve Y)) : IsSheafFor P R := isSheafFor_subsieve_aux P h (by simpa using trans (𝟙 _)) fun _ f _ => (trans f).isSeparatedFor section Arrows variable {B : C} {I : Type*} {X : I → C} (π : (i : I) → X i ⟶ B) (P) /-- A more explicit version of `FamilyOfElements.Compatible` for a `Presieve.ofArrows`. -/ def Arrows.Compatible (x : (i : I) → P.obj (op (X i))) : Prop := ∀ i j Z (gi : Z ⟶ X i) (gj : Z ⟶ X j), gi ≫ π i = gj ≫ π j → P.map gi.op (x i) = P.map gj.op (x j) lemma FamilyOfElements.isAmalgamation_iff_ofArrows (x : FamilyOfElements P (ofArrows X π)) (t : P.obj (op B)) : x.IsAmalgamation t ↔ ∀ (i : I), P.map (π i).op t = x _ (ofArrows.mk i) := ⟨fun h i ↦ h _ (ofArrows.mk i), fun h _ f ⟨i⟩ ↦ h i⟩ namespace Arrows.Compatible variable {x : (i : I) → P.obj (op (X i))} variable {P π} theorem exists_familyOfElements (hx : Compatible P π x) : ∃ (x' : FamilyOfElements P (ofArrows X π)), ∀ (i : I), x' _ (ofArrows.mk i) = x i := by choose i h h' using @ofArrows_surj _ _ _ _ _ π exact ⟨fun Y f hf ↦ P.map (eqToHom (h f hf).symm).op (x _), fun j ↦ (hx _ j (X j) _ (𝟙 _) <| by rw [← h', id_comp]).trans <| by simp⟩ variable (hx : Compatible P π x) /-- A `FamilyOfElements` associated to an explicit family of elements. -/ noncomputable def familyOfElements : FamilyOfElements P (ofArrows X π) := (exists_familyOfElements hx).choose @[simp] theorem familyOfElements_ofArrows_mk (i : I) : hx.familyOfElements _ (ofArrows.mk i) = x i := (exists_familyOfElements hx).choose_spec _ theorem familyOfElements_compatible : hx.familyOfElements.Compatible := by rintro Y₁ Y₂ Z g₁ g₂ f₁ f₂ ⟨i⟩ ⟨j⟩ hgf simp [hx i j Z g₁ g₂ hgf] end Arrows.Compatible theorem isSheafFor_arrows_iff : (ofArrows X π).IsSheafFor P ↔ (∀ (x : (i : I) → P.obj (op (X i))), Arrows.Compatible P π x → ∃! t, ∀ i, P.map (π i).op t = x i) := by refine ⟨fun h x hx ↦ ?_, fun h x hx ↦ ?_⟩ · obtain ⟨t, ht₁, ht₂⟩ := h _ hx.familyOfElements_compatible refine ⟨t, fun i ↦ ?_, fun t' ht' ↦ ht₂ _ fun _ _ ⟨i⟩ ↦ ?_⟩ · rw [ht₁ _ (ofArrows.mk i), hx.familyOfElements_ofArrows_mk] · rw [ht', hx.familyOfElements_ofArrows_mk] · obtain ⟨t, hA, ht⟩ := h (fun i ↦ x (π i) (ofArrows.mk _)) (fun i j Z gi gj ↦ hx gi gj (ofArrows.mk _) (ofArrows.mk _)) exact ⟨t, fun Y f ⟨i⟩ ↦ hA i, fun y hy ↦ ht y (fun i ↦ hy (π i) (ofArrows.mk _))⟩ variable [(ofArrows X π).HasPairwisePullbacks] /-- A more explicit version of `FamilyOfElements.PullbackCompatible` for a `Presieve.ofArrows`. -/ def Arrows.PullbackCompatible (x : (i : I) → P.obj (op (X i))) : Prop := ∀ i j, P.map (pullback.fst (π i) (π j)).op (x i) = P.map (pullback.snd (π i) (π j)).op (x j) theorem Arrows.pullbackCompatible_iff (x : (i : I) → P.obj (op (X i))) : Compatible P π x ↔ PullbackCompatible P π x := by refine ⟨fun t i j ↦ ?_, fun t i j Z gi gj comm ↦ ?_⟩ · apply t exact pullback.condition · rw [← pullback.lift_fst _ _ comm, op_comp, FunctorToTypes.map_comp_apply, t i j, ← FunctorToTypes.map_comp_apply, ← op_comp, pullback.lift_snd] theorem isSheafFor_arrows_iff_pullbacks : (ofArrows X π).IsSheafFor P ↔ (∀ (x : (i : I) → P.obj (op (X i))), Arrows.PullbackCompatible P π x → ∃! t, ∀ i, P.map (π i).op t = x i) := by simp_rw [← Arrows.pullbackCompatible_iff, isSheafFor_arrows_iff] end Arrows @[simp] lemma isSeparatedFor_singleton {X Y : C} {f : X ⟶ Y} : Presieve.IsSeparatedFor P (.singleton f) ↔ Function.Injective (P.map f.op) := by rw [IsSeparatedFor, Equiv.forall_congr_left (Presieve.FamilyOfElements.singletonEquiv P f)] simp_rw [FamilyOfElements.isAmalgamation_singleton_iff, FamilyOfElements.singletonEquiv_symm_apply_self, Function.Injective] aesop lemma isSheafFor_singleton {X Y : C} {f : X ⟶ Y} : Presieve.IsSheafFor P (.singleton f) ↔ ∀ (x : P.obj (op X)), (∀ {Z : C} (p₁ p₂ : Z ⟶ X), p₁ ≫ f = p₂ ≫ f → P.map p₁.op x = P.map p₂.op x) → ∃! y, P.map f.op y = x := by rw [IsSheafFor, Equiv.forall_congr_left (Presieve.FamilyOfElements.singletonEquiv P f)] simp_rw [FamilyOfElements.compatible_singleton_iff, FamilyOfElements.isAmalgamation_singleton_iff, FamilyOfElements.singletonEquiv_symm_apply_self] end Presieve end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Preserves.lean
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Opposites.Products import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Sites.EqualizerSheafCondition /-! # Sheaves preserve products We prove that a presheaf which satisfies the sheaf condition with respect to certain presieves preserve "the corresponding products". ## Main results More precisely, given a presheaf `F : Cᵒᵖ ⥤ Type*`, we have: * If `F` satisfies the sheaf condition with respect to the empty sieve on the initial object of `C`, then `F` preserves terminal objects. See `preservesTerminalOfIsSheafForEmpty`. * If `F` furthermore satisfies the sheaf condition with respect to the presieve consisting of the inclusion arrows in a coproduct in `C`, then `F` preserves the corresponding product. See `preservesProductOfIsSheafFor`. * If `F` preserves a product, then it satisfies the sheaf condition with respect to the corresponding presieve of arrows. See `isSheafFor_of_preservesProduct`. -/ universe v u w namespace CategoryTheory.Presieve variable {C : Type u} [Category.{v} C] {I : C} (F : Cᵒᵖ ⥤ Type w) open Limits Opposite variable (hF : (ofArrows (X := I) Empty.elim Empty.instIsEmpty.elim).IsSheafFor F) section Terminal variable (I) in /-- If `F` is a presheaf which satisfies the sheaf condition with respect to the empty presieve on any object, then `F` takes that object to the terminal object. -/ noncomputable def isTerminal_of_isSheafFor_empty_presieve : IsTerminal (F.obj (op I)) := by refine @IsTerminal.ofUnique _ _ _ fun Y ↦ ?_ choose t h using hF (by tauto) (by tauto) exact ⟨⟨fun _ ↦ t⟩, fun a ↦ by ext; exact h.2 _ (by tauto)⟩ include hF in /-- If `F` is a presheaf which satisfies the sheaf condition with respect to the empty presieve on the initial object, then `F` preserves terminal objects. -/ lemma preservesTerminal_of_isSheaf_for_empty (hI : IsInitial I) : PreservesLimit (Functor.empty.{0} Cᵒᵖ) F := have := hI.hasInitial (preservesTerminal_of_iso F ((F.mapIso (terminalIsoIsTerminal (terminalOpOfInitial initialIsInitial)) ≪≫ (F.mapIso (initialIsoIsInitial hI).symm.op) ≪≫ (terminalIsoIsTerminal (isTerminal_of_isSheafFor_empty_presieve I F hF)).symm))) end Terminal section Product variable (hI : IsInitial I) -- This is the data of a particular disjoint coproduct in `C`. variable {α : Type*} [Small.{w} α] {X : α → C} (c : Cofan X) (hc : IsColimit c) theorem piComparison_fac : have : HasCoproduct X := ⟨⟨c, hc⟩⟩ piComparison F (fun x ↦ op (X x)) = F.map (opCoproductIsoProduct' hc (productIsProduct _)).inv ≫ Equalizer.Presieve.Arrows.forkMap F X c.inj := by have : HasCoproduct X := ⟨⟨c, hc⟩⟩ dsimp only [Equalizer.Presieve.Arrows.forkMap] have h : Pi.lift (fun i ↦ F.map (c.inj i).op) = F.map (Pi.lift (fun i ↦ (c.inj i).op)) ≫ piComparison F _ := by simp rw [h, ← Category.assoc, ← Functor.map_comp] have hh : Pi.lift (fun i ↦ (c.inj i).op) = (productIsProduct (op <| X ·)).lift c.op := by simp [Pi.lift, productIsProduct] rw [hh, ← desc_op_comp_opCoproductIsoProduct'_hom hc] simp variable [(ofArrows X c.inj).HasPairwisePullbacks] include hc in /-- If `F` preserves a particular product, then it `IsSheafFor` the corresponding presieve of arrows. -/ theorem isSheafFor_of_preservesProduct [PreservesLimit (Discrete.functor (fun x ↦ op (X x))) F] : (ofArrows X c.inj).IsSheafFor F := by rw [Equalizer.Presieve.Arrows.sheaf_condition, Limits.Types.type_equalizer_iff_unique] have : HasCoproduct X := ⟨⟨c, hc⟩⟩ have hi : IsIso (piComparison F (fun x ↦ op (X x))) := inferInstance rw [piComparison_fac (hc := hc), isIso_iff_bijective, Function.bijective_iff_existsUnique] at hi intro b _ obtain ⟨t, ht₁, ht₂⟩ := hi b refine ⟨F.map ((opCoproductIsoProduct' hc (productIsProduct _)).inv) t, ht₁, fun y hy ↦ ?_⟩ apply_fun F.map ((opCoproductIsoProduct' hc (productIsProduct _)).hom) using injective_of_mono _ simp [← FunctorToTypes.map_comp_apply, ht₂ (F.map ((opCoproductIsoProduct' hc (productIsProduct _)).hom) y) (by simp [← hy])] variable [HasInitial C] [∀ i, Mono (c.inj i)] (hd : Pairwise fun i j => IsPullback (initial.to _) (initial.to _) (c.inj i) (c.inj j)) include hd hF hI in /-- The two parallel maps in the equalizer diagram for the sheaf condition corresponding to the inclusion maps in a disjoint coproduct are equal. -/ theorem firstMap_eq_secondMap : Equalizer.Presieve.Arrows.firstMap F X c.inj = Equalizer.Presieve.Arrows.secondMap F X c.inj := by ext a ⟨i, j⟩ simp only [Equalizer.Presieve.Arrows.firstMap, Types.pi_lift_π_apply, types_comp_apply, Equalizer.Presieve.Arrows.secondMap] by_cases hi : i = j · rw [hi, Mono.right_cancellation _ _ pullback.condition] · have := preservesTerminal_of_isSheaf_for_empty F hF hI apply_fun (F.mapIso ((hd hi).isoPullback).op ≪≫ F.mapIso (terminalIsoIsTerminal (terminalOpOfInitial initialIsInitial)).symm ≪≫ (PreservesTerminal.iso F)).hom using injective_of_mono _ ext ⟨i⟩ exact i.elim include hc hd hF hI in /-- If `F` is a presheaf which `IsSheafFor` a presieve of arrows and the empty presieve, then it preserves the product corresponding to the presieve of arrows. -/ lemma preservesProduct_of_isSheafFor (hF' : (ofArrows X c.inj).IsSheafFor F) : PreservesLimit (Discrete.functor (fun x ↦ op (X x))) F := by have : HasCoproduct X := ⟨⟨c, hc⟩⟩ refine @PreservesProduct.of_iso_comparison _ _ _ _ F _ (fun x ↦ op (X x)) _ _ ?_ rw [piComparison_fac (hc := hc)] refine IsIso.comp_isIso' inferInstance ?_ rw [isIso_iff_bijective, Function.bijective_iff_existsUnique] rw [Equalizer.Presieve.Arrows.sheaf_condition, Limits.Types.type_equalizer_iff_unique] at hF' exact fun b ↦ hF' b (congr_fun (firstMap_eq_secondMap F hF hI c hd) b) include hc hd hF hI in theorem isSheafFor_iff_preservesProduct : (ofArrows X c.inj).IsSheafFor F ↔ PreservesLimit (Discrete.functor (fun x ↦ op (X x))) F := ⟨fun hF' ↦ preservesProduct_of_isSheafFor _ hF hI c hc hd hF', fun _ ↦ isSheafFor_of_preservesProduct F c hc⟩ end Product end CategoryTheory.Presieve
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Precoverage.lean
import Mathlib.CategoryTheory.Limits.Preserves.Creates.Pullbacks import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Sites.Sieves import Mathlib.Order.ConditionallyCompleteLattice.Basic /-! # Precoverages A precoverage `K` on a category `C` is a set of presieves associated to every object `X : C`, called "covering presieves". There are no conditions on this set. Common extensions of a precoverage are: - `CategoryTheory.Coverage`: A coverage is a precoverage that satisfies a pullback compatibility condition, saying that whenever `S` is a covering presieve on `X` and `f : Y ⟶ X` is a morphism, then there exists some covering sieve `T` on `Y` such that `T` factors through `S` along `f`. - `CategoryTheory.Pretopology`: If `C` has pullbacks, a pretopology on `C` is a precoverage that has isomorphisms and is stable under pullback and refinement. These two are defined in later files. For precoverages, we define stability conditions: - `CategoryTheory.Precoverage.HasIsos`: Singleton presieves by isomorphisms are covering. - `CategoryTheory.Precoverage.IsStableUnderBaseChange`: The pullback of a covering presieve is again covering. - `CategoryTheory.Precoverage.IsStableUnderComposition`: Refining a covering presieve by covering presieves yields a covering presieve. -/ universe w w' v u namespace CategoryTheory /-- A precoverage is a collection of *covering* presieves on every object `X : C`. See `CategoryTheory.Coverage` and `CategoryTheory.Pretopology` for common extensions of this. -/ @[ext] structure Precoverage (C : Type*) [Category C] where /-- The collection of covering presieves for an object `X`. -/ coverings : ∀ (X : C), Set (Presieve X) namespace Precoverage variable {C : Type u} [Category.{v} C] instance : CoeFun (Precoverage C) (fun _ => (X : C) → Set (Presieve X)) where coe := coverings instance : PartialOrder (Precoverage C) where le A B := A.coverings ≤ B.coverings le_refl _ _ := le_refl _ le_trans _ _ _ h1 h2 X := le_trans (h1 X) (h2 X) le_antisymm _ _ h1 h2 := Precoverage.ext <| funext <| fun X => le_antisymm (h1 X) (h2 X) instance : Min (Precoverage C) where min A B := ⟨A.coverings ⊓ B.coverings⟩ instance : Max (Precoverage C) where max A B := ⟨A.coverings ⊔ B.coverings⟩ instance : SupSet (Precoverage C) where sSup A := ⟨⨆ K ∈ A, K.coverings⟩ instance : InfSet (Precoverage C) where sInf A := ⟨⨅ K ∈ A, K.coverings⟩ instance : Top (Precoverage C) where top.coverings _ := .univ instance : Bot (Precoverage C) where bot.coverings _ := ∅ instance : CompleteLattice (Precoverage C) := Function.Injective.completeLattice Precoverage.coverings (fun _ _ hab ↦ Precoverage.ext hab) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl) rfl rfl /-- A precoverage has isomorphisms if singleton presieves by isomorphisms are covering. -/ class HasIsos (J : Precoverage C) : Prop where mem_coverings_of_isIso {S T : C} (f : S ⟶ T) [IsIso f] : .singleton f ∈ J T /-- A precoverage is stable under base change if pullbacks of covering presieves are covering presieves. Use `Precoverage.mem_coverings_of_isPullback` for less universe restrictions. Note: This is stronger than the analogous requirement for a `Pretopology`, because `IsPullback` does not imply equality with the (arbitrarily) chosen pullbacks in `C`. -/ class IsStableUnderBaseChange (J : Precoverage C) : Prop where mem_coverings_of_isPullback {ι : Type (max u v)} {S : C} {X : ι → C} (f : ∀ i, X i ⟶ S) (hR : Presieve.ofArrows X f ∈ J S) {Y : C} (g : Y ⟶ S) {P : ι → C} (p₁ : ∀ i, P i ⟶ Y) (p₂ : ∀ i, P i ⟶ X i) (h : ∀ i, IsPullback (p₁ i) (p₂ i) g (f i)) : .ofArrows P p₁ ∈ J Y /-- A precoverage is stable under composition if the indexed composition of coverings is again a covering. Use `Precoverage.comp_mem_coverings` for less universe restrictions. Note: This is stronger than the analogous requirement for a `Pretopology`, because this is in general not equal to a `Presieve.bind`. -/ class IsStableUnderComposition (J : Precoverage C) : Prop where comp_mem_coverings {ι : Type (max u v)} {S : C} {X : ι → C} (f : ∀ i, X i ⟶ S) (hf : Presieve.ofArrows X f ∈ J S) {σ : ι → Type (max u v)} {Y : ∀ (i : ι), σ i → C} (g : ∀ i j, Y i j ⟶ X i) (hg : ∀ i, Presieve.ofArrows (Y i) (g i) ∈ J (X i)) : .ofArrows (fun p : Σ i, σ i ↦ Y _ p.2) (fun _ ↦ g _ _ ≫ f _) ∈ J S /-- A precoverage is stable under `⊔` if whenever `R` and `S` are coverings, also `R ⊔ S` is a covering. -/ class IsStableUnderSup (J : Precoverage C) where sup_mem_coverings {X : C} {R S : Presieve X} (hR : R ∈ J X) (hS : S ∈ J X) : R ⊔ S ∈ J X /-- A precoverage has pullbacks, if every covering presieve has pullbacks along arbitrary morphisms. -/ class HasPullbacks (J : Precoverage C) where hasPullbacks_of_mem {X Y : C} {R : Presieve Y} (f : X ⟶ Y) (hR : R ∈ J Y) : R.HasPullbacks f alias mem_coverings_of_isIso := HasIsos.mem_coverings_of_isIso alias sup_mem_coverings := IsStableUnderSup.sup_mem_coverings alias hasPullbacks_of_mem := HasPullbacks.hasPullbacks_of_mem attribute [local simp] Presieve.ofArrows.obj_idx Presieve.ofArrows.hom_idx in lemma mem_coverings_of_isPullback {J : Precoverage C} [IsStableUnderBaseChange J] {ι : Type w} {S : C} {X : ι → C} (f : ∀ i, X i ⟶ S) (hR : Presieve.ofArrows X f ∈ J S) {Y : C} (g : Y ⟶ S) {P : ι → C} (p₁ : ∀ i, P i ⟶ Y) (p₂ : ∀ i, P i ⟶ X i) (h : ∀ i, IsPullback (p₁ i) (p₂ i) g (f i)) : .ofArrows P p₁ ∈ J Y := by -- We need to construct `max u v`-indexed families with the same presieves. -- Because `f` needs not be injective, the indexing type is a sum. let a (i : (Presieve.ofArrows X f).uncurry ⊕ (Presieve.ofArrows P p₁).uncurry) : ι := i.elim (fun i ↦ i.2.idx) (fun i ↦ i.2.idx) convert_to Presieve.ofArrows (P ∘ a) (fun i ↦ p₁ (a i)) ∈ _ · refine le_antisymm (fun Z g hg ↦ ?_) fun Z g ⟨i⟩ ↦ ⟨a i⟩ exact .mk' (Sum.inr ⟨⟨_, _⟩, hg⟩) (by cat_disch) (by cat_disch) · refine IsStableUnderBaseChange.mem_coverings_of_isPullback (fun i ↦ f (a i)) ?_ g _ (fun i ↦ p₂ (a i)) fun i ↦ h _ convert hR refine le_antisymm (fun Z g ⟨i⟩ ↦ .mk _) fun Z g hg ↦ ?_ exact .mk' (Sum.inl ⟨⟨_, _⟩, hg⟩) (by cat_disch) (by cat_disch) attribute [local simp] Presieve.ofArrows.obj_idx Presieve.ofArrows.hom_idx in lemma comp_mem_coverings {J : Precoverage C} [IsStableUnderComposition J] {ι : Type w} {S : C} {X : ι → C} (f : ∀ i, X i ⟶ S) (hf : Presieve.ofArrows X f ∈ J S) {σ : ι → Type w'} {Y : ∀ (i : ι), σ i → C} (g : ∀ i j, Y i j ⟶ X i) (hg : ∀ i, Presieve.ofArrows (Y i) (g i) ∈ J (X i)) : .ofArrows (fun p : Σ i, σ i ↦ Y _ p.2) (fun _ ↦ g _ _ ≫ f _) ∈ J S := by -- We need to construct `max u v`-indexed families with the same presieves. -- Because `f` and `g` need not be injective, the indexing type is a sigma of sums. let ι' : Type (max u v) := (Presieve.ofArrows X f).uncurry let σ' (i : ι') : Type (max u v) := (Presieve.ofArrows (Y i.2.idx) (g i.2.idx)).uncurry let α : Type (max u v) := (Presieve.ofArrows (fun p : Σ i, σ i ↦ Y _ p.2) (fun _ ↦ g _ _ ≫ f _)).uncurry let τ' (a : α) : Type (max u v) := (Presieve.ofArrows (Y a.2.idx.1) (g a.2.idx.1)).uncurry let fib (i : ι' ⊕ α) := i.elim (fun i ↦ σ' i) (fun i ↦ Unit ⊕ τ' i) let incl (p : ι' ⊕ α) : ι := p.elim (fun i ↦ i.2.idx) (fun i ↦ i.2.idx.1) let fibincl (i : ι' ⊕ α) (j : fib i) : σ (incl i) := match i with | .inl i => j.2.idx | .inr i => j.elim (fun _ ↦ i.2.idx.2) (fun i ↦ i.2.idx) convert_to Presieve.ofArrows _ (fun p : Σ (i : ι' ⊕ α), fib i ↦ g (incl p.1) (fibincl _ p.2) ≫ f (incl p.1)) ∈ J.coverings S · refine le_antisymm (fun T u hu ↦ ?_) fun T u ⟨p⟩ ↦ .mk (Sigma.mk (incl p.1) (fibincl p.1 p.2)) exact .mk' ⟨Sum.inr ⟨⟨_, _⟩, hu⟩, .inl ⟨⟩⟩ hu.obj_idx.symm hu.eq_eqToHom_comp_hom_idx · refine IsStableUnderComposition.comp_mem_coverings (f := fun i ↦ f (incl i)) (g := fun i j ↦ g (incl i) (fibincl i j)) ?_ fun i ↦ ?_ · convert hf refine le_antisymm (fun T u ⟨p⟩ ↦ .mk _) fun T u hu ↦ ?_ exact .mk' (Sum.inl ⟨⟨_, _⟩, hu⟩) (by cat_disch) (by cat_disch) · convert hg (incl i) refine le_antisymm (fun T u ⟨p⟩ ↦ .mk _) fun T u hu ↦ ?_ match i with | .inl i => exact .mk' ⟨⟨_, _⟩, hu⟩ (by cat_disch) (by cat_disch) | .inr i => exact .mk' (.inr ⟨⟨_, _⟩, hu⟩) (by cat_disch) (by cat_disch) instance (J : Precoverage C) [Limits.HasPullbacks C] : J.HasPullbacks where hasPullbacks_of_mem := inferInstance lemma pullbackArrows_mem {J : Precoverage C} [IsStableUnderBaseChange J] {X Y : C} (f : X ⟶ Y) {R : Presieve Y} (hR : R ∈ J Y) [R.HasPullbacks f] : R.pullbackArrows f ∈ J X := by obtain ⟨ι, Z, g, rfl⟩ := R.exists_eq_ofArrows have (i : ι) : Limits.HasPullback (g i) f := Presieve.hasPullback f (Presieve.ofArrows.mk i) rw [← Presieve.ofArrows_pullback] exact mem_coverings_of_isPullback _ hR _ _ _ fun i ↦ (IsPullback.of_hasPullback _ _).flip instance (J K : Precoverage C) [HasIsos J] [HasIsos K] : HasIsos (J ⊓ K) where mem_coverings_of_isIso f _ := ⟨mem_coverings_of_isIso f, mem_coverings_of_isIso f⟩ instance (J K : Precoverage C) [IsStableUnderBaseChange J] [IsStableUnderBaseChange K] : IsStableUnderBaseChange (J ⊓ K) where mem_coverings_of_isPullback _ hf _ _ _ _ _ h := ⟨mem_coverings_of_isPullback _ hf.1 _ _ _ h, mem_coverings_of_isPullback _ hf.2 _ _ _ h⟩ instance (J K : Precoverage C) [IsStableUnderComposition J] [IsStableUnderComposition K] : IsStableUnderComposition (J ⊓ K) where comp_mem_coverings _ h _ _ _ H := ⟨comp_mem_coverings _ h.1 _ fun i ↦ (H i).1, comp_mem_coverings _ h.2 _ fun i ↦ (H i).2⟩ instance (J K : Precoverage C) [IsStableUnderSup J] [IsStableUnderSup K] : IsStableUnderSup (J ⊓ K) where sup_mem_coverings hR hS := ⟨J.sup_mem_coverings hR.1 hS.1, K.sup_mem_coverings hR.2 hS.2⟩ section Functoriality variable {D : Type*} [Category D] {F : C ⥤ D} variable {J K : Precoverage D} open Limits /-- If `J` is a precoverage on `D`, we obtain a precoverage on `C` by declaring a presieve on `D` to be covering if its image under `F` is. -/ def comap (F : C ⥤ D) (J : Precoverage D) : Precoverage C where coverings Y R := R.map F ∈ J (F.obj Y) @[simp] lemma mem_comap_iff {X : C} {R : Presieve X} : R ∈ J.comap F X ↔ R.map F ∈ J (F.obj X) := Iff.rfl lemma comap_inf : (J ⊓ K).comap F = J.comap F ⊓ K.comap F := rfl @[simp] lemma comap_id (K : Precoverage C) : K.comap (𝟭 C) = K := by ext simp instance [HasIsos J] : HasIsos (J.comap F) where mem_coverings_of_isIso {S T} f hf := by simpa using mem_coverings_of_isIso (F.map f) instance [IsStableUnderComposition J] : IsStableUnderComposition (J.comap F) where comp_mem_coverings {ι} S Y f hf σ Z g hg := by simp only [mem_comap_iff, Presieve.map_ofArrows, Functor.map_comp] at hf hg ⊢ exact J.comp_mem_coverings _ hf _ hg instance [PreservesLimitsOfShape WalkingCospan F] [IsStableUnderBaseChange J] : IsStableUnderBaseChange (J.comap F) where mem_coverings_of_isPullback {ι} S Y f hf Z g P p₁ p₂ h := by simp only [mem_comap_iff, Presieve.map_ofArrows] at hf ⊢ exact mem_coverings_of_isPullback _ hf _ _ _ fun i ↦ CategoryTheory.Functor.map_isPullback F (h i) instance [CreatesLimitsOfShape WalkingCospan F] [HasPullbacks J] : HasPullbacks (J.comap F) where hasPullbacks_of_mem {X Y} R f hR := by refine ⟨fun {Z g} hg ↦ ?_⟩ have : (Presieve.map F R).HasPullbacks (F.map f) := J.hasPullbacks_of_mem (F.map f) hR have : HasPullback (F.map g) (F.map f) := (R.map F).hasPullback _ (R.map_map hg) exact .of_createsLimit F g f end Functoriality end Precoverage end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Over.lean
import Mathlib.CategoryTheory.Sites.CoverLifting import Mathlib.CategoryTheory.Sites.CoverPreserving import Mathlib.CategoryTheory.Sites.Coverage import Mathlib.CategoryTheory.Limits.Constructions.Over.Connected import Mathlib.CategoryTheory.Limits.Shapes.Connected /-! Localization In this file, given a Grothendieck topology `J` on a category `C` and `X : C`, we construct a Grothendieck topology `J.over X` on the category `Over X`. In order to do this, we first construct a bijection `Sieve.overEquiv Y : Sieve Y ≃ Sieve Y.left` for all `Y : Over X`. Then, as it is stated in SGA 4 III 5.2.1, a sieve of `Y : Over X` is covering for `J.over X` if and only if the corresponding sieve of `Y.left` is covering for `J`. As a result, the forgetful functor `Over.forget X : Over X ⥤ X` is both cover-preserving and cover-lifting. -/ universe v' v u' u namespace CategoryTheory open Category variable {C : Type u} [Category.{v} C] @[simp] lemma Presieve.map_functorPullback_overForget {X : C} {Y : Over X} (R : Presieve Y.left) : Presieve.map (Over.forget X) (.functorPullback (Over.forget X) R) = R := by refine le_antisymm (map_functorPullback _) fun Z g hg ↦ ?_ let g' : Over.mk (g ≫ Y.hom) ⟶ Y := Over.homMk g exact Presieve.map.of (u := g') hg namespace Sieve /-- The equivalence `Sieve Y ≃ Sieve Y.left` for all `Y : Over X`. -/ def overEquiv {X : C} (Y : Over X) : Sieve Y ≃ Sieve Y.left where toFun S := Sieve.functorPushforward (Over.forget X) S invFun S' := Sieve.functorPullback (Over.forget X) S' left_inv S := by ext Z g dsimp [Presieve.functorPullback, Presieve.functorPushforward] constructor · rintro ⟨W, a, b, h, w⟩ let c : Z ⟶ W := Over.homMk b (by rw [← Over.w g, w, assoc, Over.w a]) rw [show g = c ≫ a by ext; exact w] exact S.downward_closed h _ · intro h exact ⟨Z, g, 𝟙 _, h, by simp⟩ right_inv S := by ext Z g dsimp [Presieve.functorPullback, Presieve.functorPushforward] constructor · rintro ⟨W, a, b, h, rfl⟩ exact S.downward_closed h _ · intro h exact ⟨Over.mk ((g ≫ Y.hom)), Over.homMk g, 𝟙 _, h, by simp⟩ @[simp] lemma overEquiv_top {X : C} (Y : Over X) : overEquiv Y ⊤ = ⊤ := by ext Z g simp only [top_apply, iff_true] dsimp [overEquiv, Presieve.functorPushforward] exact ⟨Y, 𝟙 Y, g, by simp, by simp⟩ @[simp] lemma overEquiv_symm_top {X : C} (Y : Over X) : (overEquiv Y).symm ⊤ = ⊤ := (overEquiv Y).injective (by simp) lemma overEquiv_le_overEquiv_iff {X : C} {Y : Over X} (R₁ R₂ : Sieve Y) : R₁.overEquiv Y ≤ R₂.overEquiv Y ↔ R₁ ≤ R₂ := by refine ⟨fun h ↦ ?_, fun h ↦ Sieve.functorPushforward_monotone _ _ h⟩ replace h : (overEquiv Y).symm (R₁.overEquiv Y) ≤ (overEquiv Y).symm (R₂.overEquiv Y) := Sieve.functorPullback_monotone _ _ h simpa using h lemma overEquiv_pullback {X : C} {Y₁ Y₂ : Over X} (f : Y₁ ⟶ Y₂) (S : Sieve Y₂) : overEquiv _ (S.pullback f) = (overEquiv _ S).pullback f.left := by ext Z g dsimp [overEquiv, Presieve.functorPushforward] constructor · rintro ⟨W, a, b, h, rfl⟩ exact ⟨W, a ≫ f, b, h, by simp⟩ · rintro ⟨W, a, b, h, w⟩ let T := Over.mk (b ≫ W.hom) let c : T ⟶ Y₁ := Over.homMk g (by dsimp [T]; rw [← Over.w a, ← reassoc_of% w, Over.w f]) let d : T ⟶ W := Over.homMk b refine ⟨T, c, 𝟙 Z, ?_, by simp [T, c]⟩ rw [show c ≫ f = d ≫ a by ext; exact w] exact S.downward_closed h _ lemma overEquiv_symm_pullback {X : C} {Y₁ Y₂ : Over X} (f : Y₁ ⟶ Y₂) (S : Sieve Y₂.left) : (overEquiv Y₁).symm (pullback f.left S) = pullback f ((overEquiv Y₂).symm S) := functorPullback_pullback _ _ _ @[simp] lemma overEquiv_symm_iff {X : C} {Y : Over X} (S : Sieve Y.left) {Z : Over X} (f : Z ⟶ Y) : (overEquiv Y).symm S f ↔ S f.left := by rfl lemma overEquiv_iff {X : C} {Y : Over X} (S : Sieve Y) {Z : C} (f : Z ⟶ Y.left) : overEquiv Y S f ↔ S (Over.homMk f : Over.mk (f ≫ Y.hom) ⟶ Y) := by obtain ⟨S, rfl⟩ := (overEquiv Y).symm.surjective S simp lemma overEquiv_generate {X : C} {Y : Over X} (R : Presieve Y) : overEquiv Y (.generate R) = .generate (Presieve.functorPushforward (Over.forget X) R) := by refine le_antisymm (fun Z g hg ↦ ?_) ?_ · rw [overEquiv_iff] at hg obtain ⟨W, u, v, hv, huv⟩ := hg exact ⟨W.left, u.left, v.left, ⟨W, v, 𝟙 _, hv, by simp⟩, congr($(huv).left)⟩ · rw [generate_le_iff] rintro Z g ⟨W, u, v, hu, rfl⟩ exact (overEquiv_iff _ _).mpr ⟨W, Over.homMk v, u, hu, rfl⟩ lemma overEquiv_symm_generate {X : C} {Y : Over X} (R : Presieve Y.left) : (overEquiv Y).symm (.generate R) = .generate (Presieve.functorPullback (Over.forget X) R) := by refine le_antisymm (fun Z g hg ↦ ?_) ?_ · rw [overEquiv_symm_iff] at hg obtain ⟨W, p, q, hq, hpq⟩ := hg refine ⟨.mk (q ≫ Y.hom), Over.homMk p (by simp [reassoc_of% hpq]), Over.homMk q rfl, hq, ?_⟩ ext exact hpq · rw [generate_le_iff] exact fun Z g hg ↦ le_generate _ _ hg @[simp] lemma functorPushforward_over_map {X Y : C} (f : X ⟶ Y) (Z : Over X) (S : Sieve Z.left) : Sieve.functorPushforward (Over.map f) ((Sieve.overEquiv Z).symm S) = (Sieve.overEquiv ((Over.map f).obj Z)).symm S := by ext W g constructor · rintro ⟨T, a, b, ha, rfl⟩ exact S.downward_closed ha _ · intro hg exact ⟨Over.mk (g.left ≫ Z.hom), Over.homMk g.left, Over.homMk (𝟙 _) (by simpa using Over.w g), hg, by cat_disch⟩ end Sieve variable (J : GrothendieckTopology C) namespace GrothendieckTopology /-- The Grothendieck topology on the category `Over X` for any `X : C` that is induced by a Grothendieck topology on `C`. -/ def over (X : C) : GrothendieckTopology (Over X) where sieves Y S := Sieve.overEquiv Y S ∈ J Y.left top_mem' Y := by change _ ∈ J Y.left simp pullback_stable' Y₁ Y₂ S₁ f h₁ := by change _ ∈ J _ at h₁ ⊢ rw [Sieve.overEquiv_pullback] exact J.pullback_stable _ h₁ transitive' Y S (hS : _ ∈ J _) R hR := J.transitive hS _ (fun Z f hf => by have hf' : _ ∈ J _ := hR ((Sieve.overEquiv_iff _ _).1 hf) rw [Sieve.overEquiv_pullback] at hf' exact hf') lemma mem_over_iff {X : C} {Y : Over X} (S : Sieve Y) : S ∈ (J.over X) Y ↔ Sieve.overEquiv _ S ∈ J Y.left := by rfl lemma overEquiv_symm_mem_over {X : C} (Y : Over X) (S : Sieve Y.left) (hS : S ∈ J Y.left) : (Sieve.overEquiv Y).symm S ∈ (J.over X) Y := by simpa only [mem_over_iff, Equiv.apply_symm_apply] using hS lemma over_forget_coverPreserving (X : C) : CoverPreserving (J.over X) J (Over.forget X) where cover_preserve hS := hS lemma over_forget_compatiblePreserving (X : C) : CompatiblePreserving J (Over.forget X) where compatible {_ Z _ _ hx Y₁ Y₂ W f₁ f₂ g₁ g₂ hg₁ hg₂ h} := by let W' : Over X := Over.mk (f₁ ≫ Y₁.hom) let g₁' : W' ⟶ Y₁ := Over.homMk f₁ let g₂' : W' ⟶ Y₂ := Over.homMk f₂ (by simpa using h.symm =≫ Z.hom) exact hx g₁' g₂' hg₁ hg₂ (by ext; exact h) instance (X : C) : (Over.forget X).IsCocontinuous (J.over X) J where cover_lift hS := J.overEquiv_symm_mem_over _ _ hS instance (X : C) : (Over.forget X).IsContinuous (J.over X) J := Functor.isContinuous_of_coverPreserving (over_forget_compatiblePreserving J X) (over_forget_coverPreserving J X) /-- The pullback functor `Sheaf J A ⥤ Sheaf (J.over X) A` -/ abbrev overPullback (A : Type u') [Category.{v'} A] (X : C) : Sheaf J A ⥤ Sheaf (J.over X) A := (Over.forget X).sheafPushforwardContinuous _ _ _ lemma over_map_coverPreserving {X Y : C} (f : X ⟶ Y) : CoverPreserving (J.over X) (J.over Y) (Over.map f) where cover_preserve {U S} hS := by obtain ⟨S, rfl⟩ := (Sieve.overEquiv U).symm.surjective S rw [Sieve.functorPushforward_over_map] apply overEquiv_symm_mem_over simpa [mem_over_iff] using hS lemma over_map_compatiblePreserving {X Y : C} (f : X ⟶ Y) : CompatiblePreserving (J.over Y) (Over.map f) where compatible {F Z _ x hx Y₁ Y₂ W f₁ f₂ g₁ g₂ hg₁ hg₂ h} := by let W' : Over X := Over.mk (f₁.left ≫ Y₁.hom) let g₁' : W' ⟶ Y₁ := Over.homMk f₁.left let g₂' : W' ⟶ Y₂ := Over.homMk f₂.left (by simpa using (Over.forget _).congr_map h.symm =≫ Z.hom) let e : (Over.map f).obj W' ≅ W := Over.isoMk (Iso.refl _) (by simpa [W'] using (Over.w f₁).symm) convert congr_arg (F.val.map e.inv.op) (hx g₁' g₂' hg₁ hg₂ (by ext; exact (Over.forget _).congr_map h)) using 1 all_goals dsimp [e, W', g₁', g₂'] rw [← FunctorToTypes.map_comp_apply] apply congr_fun congr 1 rw [← op_comp] congr 1 ext simp instance {X Y : C} (f : X ⟶ Y) : (Over.map f).IsContinuous (J.over X) (J.over Y) := Functor.isContinuous_of_coverPreserving (over_map_compatiblePreserving J f) (over_map_coverPreserving J f) section variable (A : Type u') [Category.{v'} A] /-- The pullback functor `Sheaf (J.over Y) A ⥤ Sheaf (J.over X) A` induced by a morphism `f : X ⟶ Y`. -/ abbrev overMapPullback {X Y : C} (f : X ⟶ Y) : Sheaf (J.over Y) A ⥤ Sheaf (J.over X) A := (Over.map f).sheafPushforwardContinuous _ _ _ section variable {X Y : C} {f g : X ⟶ Y} (h : f = g) /-- Two identical morphisms give isomorphic `overMapPullback` functors on sheaves. -/ @[simps!] def overMapPullbackCongr : J.overMapPullback A f ≅ J.overMapPullback A g := Functor.sheafPushforwardContinuousIso (Over.mapCongr _ _ h) _ _ _ lemma overMapPullbackCongr_eq_eqToIso : J.overMapPullbackCongr A h = eqToIso (by subst h; rfl) := by aesop end /-- Applying `overMapPullback` to the identity map gives the identity functor. -/ @[simps!] def overMapPullbackId (X : C) : J.overMapPullback A (𝟙 X) ≅ 𝟭 _ := Functor.sheafPushforwardContinuousId' (Over.mapId X) _ _ /-- The composition of two `overMapPullback` functors identifies to `overMapPullback` for the composition. -/ @[simps!] def overMapPullbackComp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : J.overMapPullback A g ⋙ J.overMapPullback A f ≅ J.overMapPullback A (f ≫ g) := Functor.sheafPushforwardContinuousComp' (Over.mapComp f g).symm _ _ _ _ @[reassoc] lemma overMapPullback_comp_id {X Y : C} (f : X ⟶ Y) : (J.overMapPullbackComp A f (𝟙 Y)).inv ≫ Functor.whiskerRight (J.overMapPullbackId A Y).hom _ ≫ (Functor.leftUnitor _).hom = (overMapPullbackCongr _ _ (by simp)).hom := by ext dsimp simp only [overMapPullbackComp_inv_app_val_app, overMapPullbackId_hom_app_val_app, comp_id, ← Functor.map_comp, ← op_comp] congr cat_disch @[reassoc] lemma overMapPullback_id_comp {X Y : C} (f : X ⟶ Y) : (J.overMapPullbackComp A (𝟙 X) f).inv ≫ Functor.whiskerLeft _ (J.overMapPullbackId A X).hom ≫ (Functor.rightUnitor _).hom = (overMapPullbackCongr _ _ (by simp)).hom := by ext dsimp simp only [overMapPullbackComp_inv_app_val_app, overMapPullbackId_hom_app_val_app, Functor.sheafPushforwardContinuous_obj_val_map, Quiver.Hom.unop_op, comp_id, ← Functor.map_comp, ← op_comp] congr cat_disch @[reassoc] lemma overMapPullback_assoc {X Y Z T : C} (f : X ⟶ Y) (g : Y ⟶ Z) (h : Z ⟶ T) : (J.overMapPullbackComp A f (g ≫ h)).inv ≫ Functor.whiskerRight (J.overMapPullbackComp A g h).inv _ ≫ (Functor.associator _ _ _).hom ≫ Functor.whiskerLeft _ (J.overMapPullbackComp A f g).hom ≫ (J.overMapPullbackComp A (f ≫ g) h).hom = (overMapPullbackCongr _ _ (by simp)).hom := by ext dsimp simp only [overMapPullbackComp_inv_app_val_app, overMapPullbackComp_hom_app_val_app, Functor.sheafPushforwardContinuous_obj_val_map, Quiver.Hom.unop_op, ← Functor.map_comp, ← op_comp, id_comp, assoc] congr cat_disch end end GrothendieckTopology variable {J} /-- Given `F : Sheaf J A` and `X : C`, this is the pullback of `F` on `J.over X`. -/ abbrev Sheaf.over {A : Type u'} [Category.{v'} A] (F : Sheaf J A) (X : C) : Sheaf (J.over X) A := (J.overPullback A X).obj F section variable (K : Precoverage C) [K.HasPullbacks] [K.IsStableUnderBaseChange] /-- The Grothendieck topology on `Over X`, obtained from localizing the topology generated by the precoverage `K`, is generated by the preimage of `K`. -/ lemma over_toGrothendieck_eq_toGrothendieck_comap_forget (X : C) : K.toGrothendieck.over X = (K.comap (Over.forget X)).toGrothendieck := by refine le_antisymm ?_ ?_ · intro ⟨Y, right, (s : Y ⟶ X)⟩ R hR obtain ⟨(R : Sieve Y), rfl⟩ := (Sieve.overEquiv _).symm.surjective R simp only [GrothendieckTopology.mem_over_iff, Equiv.apply_symm_apply] at hR induction hR with | of Z S hS => rw [Sieve.overEquiv_symm_generate] exact .of _ _ (by simpa) | top => rw [Sieve.overEquiv_symm_top] simp | transitive Y R S hR H ih ih' => refine GrothendieckTopology.transitive _ (ih s) _ fun Z g hg ↦ ?_ obtain rfl : right = Z.right := Subsingleton.elim _ _ rw [← Sieve.overEquiv_symm_pullback] exact ih' hg Z.hom · rw [Precoverage.toGrothendieck_le_iff_le_toPrecoverage] intro Y R hR rw [Precoverage.mem_comap_iff] at hR rw [GrothendieckTopology.mem_toPrecoverage_iff, GrothendieckTopology.mem_over_iff, Sieve.overEquiv, Equiv.coe_fn_mk, ← Sieve.generate_map_eq_functorPushforward] exact Coverage.Saturate.of _ _ hR end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/PreservesLocallyBijective.lean
import Mathlib.CategoryTheory.Sites.DenseSubsite.Basic import Mathlib.CategoryTheory.Sites.LocallySurjective /-! # Preserving and reflecting local injectivity and surjectivity This file proves that precomposition with a cocontinuous functor preserves local injectivity and surjectivity of morphisms of presheaves, and that precomposition with a cover-preserving and cover-dense functor reflects the same properties. -/ open CategoryTheory Functor variable {C D A : Type*} [Category C] [Category D] [Category A] (J : GrothendieckTopology C) (K : GrothendieckTopology D) (H : C ⥤ D) {F G : Dᵒᵖ ⥤ A} (f : F ⟶ G) namespace CategoryTheory namespace Presheaf variable {FA : A → A → Type*} {CA : A → Type*} variable [∀ X Y, FunLike (FA X Y) (CA X) (CA Y)] [ConcreteCategory A FA] lemma isLocallyInjective_whisker [H.IsCocontinuous J K] [IsLocallyInjective K f] : IsLocallyInjective J (whiskerLeft H.op f) where equalizerSieve_mem x y h := H.cover_lift J K (equalizerSieve_mem K f x y h) lemma isLocallyInjective_of_whisker (hH : CoverPreserving J K H) [H.IsCoverDense K] [IsLocallyInjective J (whiskerLeft H.op f)] : IsLocallyInjective K f where equalizerSieve_mem {X} a b h := by apply K.transitive (H.is_cover_of_isCoverDense K X.unop) intro Y g ⟨⟨Z, lift, m, fac⟩⟩ rw [← fac, Sieve.pullback_comp] apply K.pullback_stable refine K.superset_covering (Sieve.functorPullback_pushforward_le H _) ?_ refine K.superset_covering (Sieve.functorPushforward_monotone H _ ?_) (hH.cover_preserve <| equalizerSieve_mem J (whiskerLeft H.op f) (F.map m.op a) (F.map m.op b) ?_) · intro W q hq simpa using hq · simp only [comp_obj, op_obj, whiskerLeft_app, Opposite.op_unop] rw [NatTrans.naturality_apply, NatTrans.naturality_apply, h] lemma isLocallyInjective_whisker_iff (hH : CoverPreserving J K H) [H.IsCocontinuous J K] [H.IsCoverDense K] : IsLocallyInjective J (whiskerLeft H.op f) ↔ IsLocallyInjective K f := ⟨fun _ ↦ isLocallyInjective_of_whisker J K H f hH, fun _ ↦ isLocallyInjective_whisker J K H f⟩ lemma isLocallySurjective_whisker [H.IsCocontinuous J K] [IsLocallySurjective K f] : IsLocallySurjective J (whiskerLeft H.op f) where imageSieve_mem a := H.cover_lift J K (imageSieve_mem K f a) lemma isLocallySurjective_of_whisker (hH : CoverPreserving J K H) [H.IsCoverDense K] [IsLocallySurjective J (whiskerLeft H.op f)] : IsLocallySurjective K f where imageSieve_mem {X} a := by apply K.transitive (H.is_cover_of_isCoverDense K X) intro Y g ⟨⟨Z, lift, m, fac⟩⟩ rw [← fac, Sieve.pullback_comp] apply K.pullback_stable have hh := hH.cover_preserve <| imageSieve_mem J (whiskerLeft H.op f) (G.map m.op a) refine K.superset_covering (Sieve.functorPullback_pushforward_le H _) ?_ refine K.superset_covering (Sieve.functorPushforward_monotone H _ ?_) hh intro W q ⟨x, h⟩ simp only [Sieve.functorPullback_apply, Presieve.functorPullback_mem, Sieve.pullback_apply] exact ⟨x, by simpa using h⟩ lemma isLocallySurjective_whisker_iff (hH : CoverPreserving J K H) [H.IsCocontinuous J K] [H.IsCoverDense K] : IsLocallySurjective J (whiskerLeft H.op f) ↔ IsLocallySurjective K f := ⟨fun _ ↦ isLocallySurjective_of_whisker J K H f hH, fun _ ↦ isLocallySurjective_whisker J K H f⟩ end Presheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/SheafHom.lean
import Mathlib.CategoryTheory.Sites.Over /-! Internal hom of sheaves In this file, given two sheaves `F` and `G` on a site `(C, J)` with values in a category `A`, we define a sheaf of types `sheafHom F G` which sends `X : C` to the type of morphisms between the restrictions of `F` and `G` to the categories `Over X`. We first define `presheafHom F G` when `F` and `G` are presheaves `Cᵒᵖ ⥤ A` and show that it is a sheaf when `G` is a sheaf. TODO: - turn both `presheafHom` and `sheafHom` into bifunctors - for a sheaf of types `F`, the `sheafHom` functor from `F` is right-adjoint to the product functor with `F`, i.e. for all `X` and `Y`, there is a natural bijection `(X ⨯ F ⟶ Y) ≃ (X ⟶ sheafHom F Y)`. - use these results in order to show that the category of sheaves of types is Cartesian closed -/ universe v v' u u' namespace CategoryTheory open Category Opposite Limits variable {C : Type u} [Category.{v} C] {J : GrothendieckTopology C} {A : Type u'} [Category.{v'} A] variable (F G : Cᵒᵖ ⥤ A) /-- Given two presheaves `F` and `G` on a category `C` with values in a category `A`, this `presheafHom F G` is the presheaf of types which sends an object `X : C` to the type of morphisms between the "restrictions" of `F` and `G` to the category `Over X`. -/ @[simps! obj] def presheafHom : Cᵒᵖ ⥤ Type _ where obj X := (Over.forget X.unop).op ⋙ F ⟶ (Over.forget X.unop).op ⋙ G map f := Functor.whiskerLeft (Over.map f.unop).op map_id := by rintro ⟨X⟩ ext φ ⟨Y⟩ simpa [Over.mapId] using φ.naturality ((Over.mapId X).hom.app Y).op map_comp := by rintro ⟨X⟩ ⟨Y⟩ ⟨Z⟩ ⟨f : Y ⟶ X⟩ ⟨g : Z ⟶ Y⟩ ext φ ⟨W⟩ simpa [Over.mapComp] using φ.naturality ((Over.mapComp g f).hom.app W).op variable {F G} /-- Equational lemma for the presheaf structure on `presheafHom`. It is advisable to use this lemma rather than `dsimp [presheafHom]` which may result in the need to prove equalities of objects in an `Over` category. -/ lemma presheafHom_map_app {X Y Z : C} (f : Z ⟶ Y) (g : Y ⟶ X) (h : Z ⟶ X) (w : f ≫ g = h) (α : (presheafHom F G).obj (op X)) : ((presheafHom F G).map g.op α).app (op (Over.mk f)) = α.app (op (Over.mk h)) := by subst w rfl @[simp] lemma presheafHom_map_app_op_mk_id {X Y : C} (g : Y ⟶ X) (α : (presheafHom F G).obj (op X)) : ((presheafHom F G).map g.op α).app (op (Over.mk (𝟙 Y))) = α.app (op (Over.mk g)) := presheafHom_map_app (𝟙 Y) g g (by simp) α variable (F G) /-- The sections of the presheaf `presheafHom F G` identify to morphisms `F ⟶ G`. -/ def presheafHomSectionsEquiv : (presheafHom F G).sections ≃ (F ⟶ G) where toFun s := { app := fun X => (s.1 X).app ⟨Over.mk (𝟙 _)⟩ naturality := by rintro ⟨X₁⟩ ⟨X₂⟩ ⟨f : X₂ ⟶ X₁⟩ dsimp refine Eq.trans ?_ ((s.1 ⟨X₁⟩).naturality (Over.homMk f : Over.mk f ⟶ Over.mk (𝟙 X₁)).op) rw [← s.2 f.op, presheafHom_map_app_op_mk_id] rfl } invFun f := ⟨fun _ => Functor.whiskerLeft _ f, fun _ => rfl⟩ left_inv s := by dsimp ext ⟨X⟩ ⟨Y : Over X⟩ have H := s.2 Y.hom.op dsimp at H ⊢ rw [← H] apply presheafHom_map_app_op_mk_id variable {F G} lemma PresheafHom.isAmalgamation_iff {X : C} (S : Sieve X) (x : Presieve.FamilyOfElements (presheafHom F G) S.arrows) (hx : x.Compatible) (y : (presheafHom F G).obj (op X)) : x.IsAmalgamation y ↔ ∀ (Y : C) (g : Y ⟶ X) (hg : S g), y.app (op (Over.mk g)) = (x g hg).app (op (Over.mk (𝟙 Y))) := by constructor · intro h Y g hg rw [← h g hg, presheafHom_map_app_op_mk_id] · intro h Y g hg dsimp ext ⟨W : Over Y⟩ refine (h W.left (W.hom ≫ g) (S.downward_closed hg _)).trans ?_ have H := hx (𝟙 _) W.hom (S.downward_closed hg W.hom) hg (by simp) dsimp at H simp only [FunctorToTypes.map_id_apply] at H rw [H, presheafHom_map_app_op_mk_id] rfl section variable {X : C} {S : Sieve X} (hG : ∀ ⦃Y : C⦄ (f : Y ⟶ X), IsLimit (G.mapCone (S.pullback f).arrows.cocone.op)) namespace PresheafHom.IsSheafFor variable (x : Presieve.FamilyOfElements (presheafHom F G) S.arrows) {Y : C} include hG in lemma exists_app (hx : x.Compatible) (g : Y ⟶ X) : ∃ (φ : F.obj (op Y) ⟶ G.obj (op Y)), ∀ {Z : C} (p : Z ⟶ Y) (hp : S (p ≫ g)), φ ≫ G.map p.op = F.map p.op ≫ (x (p ≫ g) hp).app ⟨Over.mk (𝟙 Z)⟩ := by let c : Cone ((Presieve.diagram (Sieve.pullback g S).arrows).op ⋙ G) := { pt := F.obj (op Y) π := { app := fun ⟨Z, hZ⟩ => F.map Z.hom.op ≫ (x _ hZ).app (op (Over.mk (𝟙 _))) naturality := by rintro ⟨Z₁, hZ₁⟩ ⟨Z₂, hZ₂⟩ ⟨f : Z₂ ⟶ Z₁⟩ dsimp rw [id_comp, assoc] have H := hx f.left (𝟙 _) hZ₁ hZ₂ (by simp) simp only [presheafHom_obj, unop_op, Functor.id_obj, op_id, FunctorToTypes.map_id_apply] at H let φ : Over.mk f.left ⟶ Over.mk (𝟙 Z₁.left) := Over.homMk f.left have H' := (x (Z₁.hom ≫ g) hZ₁).naturality φ.op dsimp at H H' ⊢ erw [← H, ← H', presheafHom_map_app_op_mk_id, ← F.map_comp_assoc, ← op_comp, Over.w f] } } use (hG g).lift c intro Z p hp exact ((hG g).fac c ⟨Over.mk p, hp⟩) /-- Auxiliary definition for `presheafHom_isSheafFor`. -/ noncomputable def app (hx : x.Compatible) (g : Y ⟶ X) : F.obj (op Y) ⟶ G.obj (op Y) := (exists_app hG x hx g).choose lemma app_cond (hx : x.Compatible) (g : Y ⟶ X) {Z : C} (p : Z ⟶ Y) (hp : S (p ≫ g)) : app hG x hx g ≫ G.map p.op = F.map p.op ≫ (x (p ≫ g) hp).app ⟨Over.mk (𝟙 Z)⟩ := (exists_app hG x hx g).choose_spec p hp end PresheafHom.IsSheafFor variable (F G S) include hG in open PresheafHom.IsSheafFor in lemma presheafHom_isSheafFor : Presieve.IsSheafFor (presheafHom F G) S.arrows := by intro x hx apply existsUnique_of_exists_of_unique · refine ⟨ { app := fun Y => app hG x hx Y.unop.hom naturality := by rintro ⟨Y₁ : Over X⟩ ⟨Y₂ : Over X⟩ ⟨φ : Y₂ ⟶ Y₁⟩ apply (hG Y₂.hom).hom_ext rintro ⟨Z : Over Y₂.left, hZ⟩ dsimp rw [assoc, assoc, app_cond hG x hx Y₂.hom Z.hom hZ, ← G.map_comp, ← op_comp] rw [app_cond hG x hx Y₁.hom (Z.hom ≫ φ.left) (by simpa using hZ), ← F.map_comp_assoc, op_comp] congr 3 simp }, ?_⟩ rw [PresheafHom.isAmalgamation_iff _ _ hx] intro Y g hg dsimp have H := app_cond hG x hx g (𝟙 _) (by simpa using hg) rw [op_id, G.map_id, comp_id, F.map_id, id_comp] at H exact H.trans (by congr; simp) · intro y₁ y₂ hy₁ hy₂ rw [PresheafHom.isAmalgamation_iff _ _ hx] at hy₁ hy₂ apply NatTrans.ext ext ⟨Y : Over X⟩ apply (hG Y.hom).hom_ext rintro ⟨Z : Over Y.left, hZ⟩ dsimp let φ : Over.mk (Z.hom ≫ Y.hom) ⟶ Y := Over.homMk Z.hom refine (y₁.naturality φ.op).symm.trans (Eq.trans ?_ (y₂.naturality φ.op)) rw [(hy₁ _ _ hZ), ← ((hy₂ _ _ hZ))] end variable (F G) lemma Presheaf.IsSheaf.hom (hG : Presheaf.IsSheaf J G) : Presheaf.IsSheaf J (presheafHom F G) := by rw [isSheaf_iff_isSheaf_of_type] intro X S hS exact presheafHom_isSheafFor F G S (fun _ _ => ((Presheaf.isSheaf_iff_isLimit J G).1 hG _ (J.pullback_stable _ hS)).some) /-- The underlying presheaf of `sheafHom F G`. It is isomorphic to `presheafHom F.1 G.1` (see `sheafHom'Iso`), but has better definitional properties. -/ def sheafHom' (F G : Sheaf J A) : Cᵒᵖ ⥤ Type _ where obj X := (J.overPullback A X.unop).obj F ⟶ (J.overPullback A X.unop).obj G map f := fun φ => (J.overMapPullback A f.unop).map φ map_id X := by ext φ : 2 exact congr_fun ((presheafHom F.1 G.1).map_id X) φ.1 map_comp f g := by ext φ : 2 exact congr_fun ((presheafHom F.1 G.1).map_comp f g) φ.1 /-- The canonical isomorphism `sheafHom' F G ≅ presheafHom F.1 G.1`. -/ def sheafHom'Iso (F G : Sheaf J A) : sheafHom' F G ≅ presheafHom F.1 G.1 := NatIso.ofComponents (fun _ => Sheaf.homEquiv.toIso) (fun _ => rfl) /-- Given two sheaves `F` and `G` on a site `(C, J)` with values in a category `A`, this `sheafHom F G` is the sheaf of types which sends an object `X : C` to the type of morphisms between the "restrictions" of `F` and `G` to the category `Over X`. -/ def sheafHom (F G : Sheaf J A) : Sheaf J (Type _) where val := sheafHom' F G cond := (Presheaf.isSheaf_of_iso_iff (sheafHom'Iso F G)).2 (G.2.hom F.1) /-- The sections of the sheaf `sheafHom F G` identify to morphisms `F ⟶ G`. -/ def sheafHomSectionsEquiv (F G : Sheaf J A) : (sheafHom F G).1.sections ≃ (F ⟶ G) := ((Functor.sectionsFunctor Cᵒᵖ).mapIso (sheafHom'Iso F G)).toEquiv.trans ((presheafHomSectionsEquiv F.1 G.1).trans Sheaf.homEquiv.symm) @[simp] lemma sheafHomSectionsEquiv_symm_apply_coe_apply {F G : Sheaf J A} (φ : F ⟶ G) (X : Cᵒᵖ) : ((sheafHomSectionsEquiv F G).symm φ).1 X = (J.overPullback A X.unop).map φ := rfl end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/CoverLifting.lean
import Mathlib.CategoryTheory.Adjunction.Restrict import Mathlib.CategoryTheory.Functor.KanExtension.Adjunction import Mathlib.CategoryTheory.Sites.Continuous import Mathlib.CategoryTheory.Sites.Sheafification /-! # Cocontinuous functors between sites. We define cocontinuous functors between sites as functors that pull covering sieves back to covering sieves. This concept is also known as *cover-lifting* or *cover-reflecting functors*. We use the original terminology and definition of SGA 4 III 2.1. However, the notion of cocontinuous functor should not be confused with the general definition of cocontinuous functors between categories as functors preserving small colimits. ## Main definitions * `CategoryTheory.Functor.IsCocontinuous`: a functor between sites is cocontinuous if it pulls back covering sieves to covering sieves * `CategoryTheory.Functor.sheafPushforwardCocontinuous`: A cocontinuous functor `G : (C, J) ⥤ (D, K)` induces a functor `Sheaf J A ⥤ Sheaf K A`. ## Main results * `CategoryTheory.ran_isSheaf_of_isCocontinuous`: If `G : C ⥤ D` is cocontinuous, then `G.op.ran` (`ₚu`) as a functor `(Cᵒᵖ ⥤ A) ⥤ (Dᵒᵖ ⥤ A)` of presheaves maps sheaves to sheaves. * `CategoryTheory.Functor.sheafAdjunctionCocontinuous`: If `G : (C, J) ⥤ (D, K)` is cocontinuous and continuous, then `G.sheafPushforwardContinuous A J K` and `G.sheafPushforwardCocontinuous A J K` are adjoint. ## References * [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.3. * [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92] * https://stacks.math.columbia.edu/tag/00XI -/ universe w' w v v₁ v₂ v₃ u u₁ u₂ u₃ noncomputable section open CategoryTheory open Opposite open CategoryTheory.Presieve.FamilyOfElements open CategoryTheory.Presieve open CategoryTheory.Limits namespace CategoryTheory section IsCocontinuous variable {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] (G : C ⥤ D) (G' : D ⥤ E) variable (J : GrothendieckTopology C) (K : GrothendieckTopology D) variable {L : GrothendieckTopology E} /-- A functor `G : (C, J) ⥤ (D, K)` between sites is called cocontinuous (SGA 4 III 2.1) if for all covering sieves `R` in `D`, `R.pullback G` is a covering sieve in `C`. -/ class Functor.IsCocontinuous : Prop where cover_lift : ∀ {U : C} {S : Sieve (G.obj U)} (_ : S ∈ K (G.obj U)), S.functorPullback G ∈ J U lemma Functor.cover_lift [G.IsCocontinuous J K] {U : C} {S : Sieve (G.obj U)} (hS : S ∈ K (G.obj U)) : S.functorPullback G ∈ J U := IsCocontinuous.cover_lift hS /-- The identity functor on a site is cocontinuous. -/ instance isCocontinuous_id : Functor.IsCocontinuous (𝟭 C) J J := ⟨fun h => by simpa using h⟩ /-- The composition of two cocontinuous functors is cocontinuous. -/ theorem isCocontinuous_comp [G.IsCocontinuous J K] [G'.IsCocontinuous K L] : (G ⋙ G').IsCocontinuous J L where cover_lift h := G.cover_lift J K (G'.cover_lift K L h) end IsCocontinuous /-! We will now prove that `G.op.ran : (Cᵒᵖ ⥤ A) ⥤ (Dᵒᵖ ⥤ A)` maps sheaves to sheaves when `G : C ⥤ D` is a cocontinuous functor. We do not follow the proofs in SGA 4 III 2.2 or <https://stacks.math.columbia.edu/tag/00XK>. Instead, we verify as directly as possible that if `F : Cᵒᵖ ⥤ A` is a sheaf, then `G.op.ran.obj F` is a sheaf. in order to do this, we use the "multifork" characterization of sheaves which involves limits in the category `A`. As `G.op.ran.obj F` is the chosen right Kan extension of `F` along `G.op : Cᵒᵖ ⥤ Dᵒᵖ`, we actually verify that any pointwise right Kan extension of `F` along `G.op` is a sheaf. -/ variable {C D : Type*} [Category C] [Category D] (G : C ⥤ D) variable {A : Type w} [Category.{w'} A] variable {J : GrothendieckTopology C} {K : GrothendieckTopology D} [G.IsCocontinuous J K] namespace RanIsSheafOfIsCocontinuous variable {G} variable {F : Cᵒᵖ ⥤ A} (hF : Presheaf.IsSheaf J F) variable {R : Dᵒᵖ ⥤ A} (α : G.op ⋙ R ⟶ F) variable (hR : (Functor.RightExtension.mk _ α).IsPointwiseRightKanExtension) variable {X : D} {S : K.Cover X} (s : Multifork (S.index R)) /-- Auxiliary definition for `lift`. -/ def liftAux {Y : C} (f : G.obj Y ⟶ X) : s.pt ⟶ F.obj (op Y) := Multifork.IsLimit.lift (hF.isLimitMultifork ⟨_, G.cover_lift J K (K.pullback_stable f S.2)⟩) (fun k ↦ s.ι (⟨_, G.map k.f ≫ f, k.hf⟩) ≫ α.app (op k.Y)) (by intro { fst := ⟨Y₁, p₁, hp₁⟩, snd := ⟨Y₂, p₂, hp₂⟩, r := ⟨W, g₁, g₂, w⟩ } dsimp at g₁ g₂ w ⊢ simp only [Category.assoc, ← α.naturality, Functor.comp_map, Functor.op_map, Quiver.Hom.unop_op] apply s.condition_assoc { fst.hf := hp₁ snd.hf := hp₂ r.g₁ := G.map g₁ r.g₂ := G.map g₂ r.w := by simpa using G.congr_map w =≫ f .. }) lemma liftAux_map {Y : C} (f : G.obj Y ⟶ X) {W : C} (g : W ⟶ Y) (i : S.Arrow) (h : G.obj W ⟶ i.Y) (w : h ≫ i.f = G.map g ≫ f) : liftAux hF α s f ≫ F.map g.op = s.ι i ≫ R.map h.op ≫ α.app _ := (Multifork.IsLimit.fac (hF.isLimitMultifork ⟨_, G.cover_lift J K (K.pullback_stable f S.2)⟩) _ _ ⟨W, g, by simpa only [Sieve.functorPullback_apply, functorPullback_mem, Sieve.pullback_apply, ← w] using S.1.downward_closed i.hf h⟩).trans (by dsimp simp only [← Category.assoc] congr 1 let r : S.Relation := { fst.f := G.map g ≫ f fst.hf := by simpa only [← w] using S.1.downward_closed i.hf h snd := i r.g₁ := 𝟙 _ r.g₂ := h r.w := by simpa using w.symm .. } simpa [r] using s.condition r ) lemma liftAux_map' {Y Y' : C} (f : G.obj Y ⟶ X) (f' : G.obj Y' ⟶ X) {W : C} (a : W ⟶ Y) (b : W ⟶ Y') (w : G.map a ≫ f = G.map b ≫ f') : liftAux hF α s f ≫ F.map a.op = liftAux hF α s f' ≫ F.map b.op := by apply hF.hom_ext ⟨_, G.cover_lift J K (K.pullback_stable (G.map a ≫ f) S.2)⟩ rintro ⟨T, g, hg⟩ dsimp have eq₁ := liftAux_map hF α s f (g ≫ a) ⟨_, _, hg⟩ (𝟙 _) (by simp) have eq₂ := liftAux_map hF α s f' (g ≫ b) ⟨_, _, hg⟩ (𝟙 _) (by simp [w]) dsimp at eq₁ eq₂ simp only [Functor.map_comp, Functor.map_id, Category.id_comp] at eq₁ eq₂ simp only [Category.assoc, eq₁, eq₂] variable {α} /-- Auxiliary definition for `isLimitMultifork` -/ def lift : s.pt ⟶ R.obj (op X) := (hR (op X)).lift (Cone.mk _ { app := fun j ↦ liftAux hF α s j.hom.unop naturality := fun j j' φ ↦ by simpa using liftAux_map' hF α s j'.hom.unop j.hom.unop (𝟙 _) φ.right.unop (Quiver.Hom.op_inj (by simpa using (StructuredArrow.w φ).symm)) }) lemma fac' (j : StructuredArrow (op X) G.op) : lift hF hR s ≫ R.map j.hom ≫ α.app j.right = liftAux hF α s j.hom.unop := by apply IsLimit.fac @[reassoc (attr := simp)] lemma fac (i : S.Arrow) : lift hF hR s ≫ R.map i.f.op = s.ι i := by apply (hR (op i.Y)).hom_ext intro j have eq := fac' hF hR s (StructuredArrow.mk (i.f.op ≫ j.hom)) dsimp at eq ⊢ simp only [Functor.map_comp, Category.assoc] at eq rw [Category.assoc, eq] simpa using liftAux_map hF α s (j.hom.unop ≫ i.f) (𝟙 _) i j.hom.unop (by simp) include hR hF in variable (K) in lemma hom_ext {W : A} {f g : W ⟶ R.obj (op X)} (h : ∀ (i : S.Arrow), f ≫ R.map i.f.op = g ≫ R.map i.f.op) : f = g := by apply (hR (op X)).hom_ext intro j apply hF.hom_ext ⟨_, G.cover_lift J K (K.pullback_stable j.hom.unop S.2)⟩ intro ⟨W, i, hi⟩ have eq := h (GrothendieckTopology.Cover.Arrow.mk _ (G.map i ≫ j.hom.unop) hi) dsimp at eq ⊢ simp only [Category.assoc, ← NatTrans.naturality, Functor.comp_map, ← Functor.map_comp_assoc, Functor.op_map, Quiver.Hom.unop_op] rw [reassoc_of% eq] variable (S) /-- Auxiliary definition for `ran_isSheaf_of_isCocontinuous` -/ def isLimitMultifork : IsLimit (S.multifork R) := Multifork.IsLimit.mk _ (lift hF hR) (fac hF hR) (fun s _ hm ↦ hom_ext K hF hR (fun i ↦ (hm i).trans (fac hF hR s i).symm)) end RanIsSheafOfIsCocontinuous variable (K) variable [∀ (F : Cᵒᵖ ⥤ A), G.op.HasPointwiseRightKanExtension F] /-- If `G` is cocontinuous, then `G.op.ran` pushes sheaves to sheaves. This is SGA 4 III 2.2. -/ @[stacks 00XK "Alternative reference. There, results are obtained under the additional assumption that `C` and `D` have pullbacks."] theorem ran_isSheaf_of_isCocontinuous (ℱ : Sheaf J A) : Presheaf.IsSheaf K (G.op.ran.obj ℱ.val) := by rw [Presheaf.isSheaf_iff_multifork] intro X S exact ⟨RanIsSheafOfIsCocontinuous.isLimitMultifork ℱ.2 (G.op.isPointwiseRightKanExtensionRanCounit ℱ.val) S⟩ variable (A J) /-- A cocontinuous functor induces a pushforward functor on categories of sheaves. -/ def Functor.sheafPushforwardCocontinuous : Sheaf J A ⥤ Sheaf K A where obj ℱ := ⟨G.op.ran.obj ℱ.val, ran_isSheaf_of_isCocontinuous _ K ℱ⟩ map f := ⟨G.op.ran.map f.val⟩ map_id ℱ := Sheaf.Hom.ext <| (ran G.op).map_id ℱ.val map_comp f g := Sheaf.Hom.ext <| (ran G.op).map_comp f.val g.val /-- `G.sheafPushforwardCocontinuous A J K : Sheaf J A ⥤ Sheaf K A` is induced by the right Kan extension functor `G.op.ran` on presheaves. -/ @[simps! hom inv] def Functor.sheafPushforwardCocontinuousCompSheafToPresheafIso : G.sheafPushforwardCocontinuous A J K ⋙ sheafToPresheaf K A ≅ sheafToPresheaf J A ⋙ G.op.ran := Iso.refl _ /- Given a cocontinuous functor `G`, the precomposition with `G.op` induces a functor on presheaves with leads to a "pullback" functor `Sheaf K A ⥤ Sheaf J A` (TODO: formalize this as `G.sheafPullbackCocontinuous A J K`) using the associated sheaf functor. It is shown in SGA 4 III 2.3 that this pullback functor is left adjoint to `G.sheafPushforwardCocontinuous A J K`. This adjunction may replace `Functor.sheafAdjunctionCocontinuous` below, and then, it could be shown that if `G` is also continuous, then we have an isomorphism `G.sheafPullbackCocontinuous A J K ≅ G.sheafPushforwardContinuous A J K` (TODO). -/ namespace Functor variable [G.IsContinuous J K] /-- Given a functor between sites that is continuous and cocontinuous, the pushforward for the continuous functor `G` is left adjoint to the pushforward for the cocontinuous functor `G`. -/ noncomputable def sheafAdjunctionCocontinuous : G.sheafPushforwardContinuous A J K ⊣ G.sheafPushforwardCocontinuous A J K := (G.op.ranAdjunction A).restrictFullyFaithful (fullyFaithfulSheafToPresheaf K A) (fullyFaithfulSheafToPresheaf J A) (G.sheafPushforwardContinuousCompSheafToPresheafIso A J K).symm (G.sheafPushforwardCocontinuousCompSheafToPresheafIso A J K).symm lemma sheafAdjunctionCocontinuous_unit_app_val (F : Sheaf K A) : ((G.sheafAdjunctionCocontinuous A J K).unit.app F).val = (G.op.ranAdjunction A).unit.app F.val := by apply ((G.op.ranAdjunction A).map_restrictFullyFaithful_unit_app (fullyFaithfulSheafToPresheaf K A) (fullyFaithfulSheafToPresheaf J A) (G.sheafPushforwardContinuousCompSheafToPresheafIso A J K).symm (G.sheafPushforwardCocontinuousCompSheafToPresheafIso A J K).symm F).trans dsimp erw [Functor.map_id] change _ ≫ 𝟙 _ ≫ 𝟙 _ = _ simp only [Category.comp_id] lemma sheafAdjunctionCocontinuous_counit_app_val (F : Sheaf J A) : ((G.sheafAdjunctionCocontinuous A J K).counit.app F).val = (G.op.ranAdjunction A).counit.app F.val := ((G.op.ranAdjunction A).map_restrictFullyFaithful_counit_app (fullyFaithfulSheafToPresheaf K A) (fullyFaithfulSheafToPresheaf J A) (G.sheafPushforwardContinuousCompSheafToPresheafIso A J K).symm (G.sheafPushforwardCocontinuousCompSheafToPresheafIso A J K).symm F).trans (by cat_disch) lemma sheafAdjunctionCocontinuous_homEquiv_apply_val {F : Sheaf K A} {H : Sheaf J A} (f : (G.sheafPushforwardContinuous A J K).obj F ⟶ H) : ((G.sheafAdjunctionCocontinuous A J K).homEquiv F H f).val = (G.op.ranAdjunction A).homEquiv F.val H.val f.val := ((sheafToPresheaf K A).congr_map (((G.op.ranAdjunction A).restrictFullyFaithful_homEquiv_apply (fullyFaithfulSheafToPresheaf K A) (fullyFaithfulSheafToPresheaf J A) (G.sheafPushforwardContinuousCompSheafToPresheafIso A J K).symm (G.sheafPushforwardCocontinuousCompSheafToPresheafIso A J K).symm f))).trans (by dsimp erw [Functor.map_id, Category.comp_id, Category.id_comp, Adjunction.homEquiv_unit]) variable [HasWeakSheafify J A] [HasWeakSheafify K A] /-- The natural isomorphism exhibiting compatibility between pushforward and sheafification. -/ def pushforwardContinuousSheafificationCompatibility [G.IsContinuous J K] : (whiskeringLeft _ _ A).obj G.op ⋙ presheafToSheaf J A ≅ presheafToSheaf K A ⋙ G.sheafPushforwardContinuous A J K := ((G.op.ranAdjunction A).comp (sheafificationAdjunction J A)).leftAdjointUniq ((sheafificationAdjunction K A).comp (G.sheafAdjunctionCocontinuous A J K)) /- Implementation: This is primarily used to prove the lemma `pullbackSheafificationCompatibility_hom_app_val`. -/ lemma toSheafify_pullbackSheafificationCompatibility (F : Dᵒᵖ ⥤ A) : toSheafify J (G.op ⋙ F) ≫ ((G.pushforwardContinuousSheafificationCompatibility A J K).hom.app F).val = whiskerLeft _ (toSheafify K _) := by let adj₁ := G.op.ranAdjunction A let adj₂ := sheafificationAdjunction J A let adj₃ := sheafificationAdjunction K A let adj₄ := G.sheafAdjunctionCocontinuous A J K change adj₂.unit.app (((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).obj F) ≫ (sheafToPresheaf J A).map (((adj₁.comp adj₂).leftAdjointUniq (adj₃.comp adj₄)).hom.app F) = ((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).map (adj₃.unit.app F) apply (adj₁.homEquiv _ _).injective have eq := (adj₁.comp adj₂).unit_leftAdjointUniq_hom_app (adj₃.comp adj₄) F rw [Adjunction.comp_unit_app, Adjunction.comp_unit_app, comp_map, Category.assoc] at eq rw [adj₁.homEquiv_unit, Functor.map_comp, eq] apply (adj₁.homEquiv _ _).symm.injective simp only [Adjunction.homEquiv_counit, map_comp, Category.assoc, Adjunction.homEquiv_unit, Adjunction.unit_naturality] congr 3 exact G.sheafAdjunctionCocontinuous_unit_app_val A J K ((presheafToSheaf K A).obj F) @[simp] lemma pushforwardContinuousSheafificationCompatibility_hom_app_val (F : Dᵒᵖ ⥤ A) : ((G.pushforwardContinuousSheafificationCompatibility A J K).hom.app F).val = sheafifyLift J (whiskerLeft G.op <| toSheafify K F) ((presheafToSheaf K A ⋙ G.sheafPushforwardContinuous A J K).obj F).cond := by apply sheafifyLift_unique apply toSheafify_pullbackSheafificationCompatibility end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/SheafOfTypes.lean
import Mathlib.CategoryTheory.Sites.Pretopology import Mathlib.CategoryTheory.Sites.IsSheafFor /-! # Sheaves of types on a Grothendieck topology Defines the notion of a sheaf of types (usually called a sheaf of sets by mathematicians) on a category equipped with a Grothendieck topology, as well as a range of equivalent conditions useful in different situations. In `Mathlib/CategoryTheory/Sites/IsSheafFor.lean` it is defined what it means for a presheaf to be a sheaf *for* a particular sieve. Given a Grothendieck topology `J`, `P` is a sheaf if it is a sheaf for every sieve in the topology. See `IsSheaf`. In the case where the topology is generated by a basis, it suffices to check `P` is a sheaf for every presieve in the pretopology. See `isSheaf_pretopology`. We also provide equivalent conditions to satisfy alternate definitions given in the literature. * Stacks: In `Equalizer.Presieve.sheaf_condition`, the sheaf condition at a presieve is shown to be equivalent to that of https://stacks.math.columbia.edu/tag/00VM (and combined with `isSheaf_pretopology`, this shows the notions of `IsSheaf` are exactly equivalent.) The condition of https://stacks.math.columbia.edu/tag/00Z8 is virtually identical to the statement of `isSheafFor_iff_yonedaSheafCondition` (since the bijection described there carries the same information as the unique existence.) * Maclane-Moerdijk [MM92]: Using `compatible_iff_sieveCompatible`, the definitions of `IsSheaf` are equivalent. There are also alternate definitions given: - Sheaf for a pretopology (Prop 1): `isSheaf_pretopology` combined with `pullbackCompatible_iff`. - Sheaf for a pretopology as equalizer (Prop 1, bis): `Equalizer.Presieve.sheaf_condition` combined with the previous. ## References * [MM92]: *Sheaves in geometry and logic*, Saunders MacLane, and Ieke Moerdijk: Chapter III, Section 4. * [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.1. * https://stacks.math.columbia.edu/tag/00VL (sheaves on a pretopology or site) * https://stacks.math.columbia.edu/tag/00ZB (sheaves on a topology) -/ universe w w' v u namespace CategoryTheory open Opposite CategoryTheory Category Limits Sieve namespace Presieve variable {C : Type u} [Category.{v} C] variable {P : Cᵒᵖ ⥤ Type w} variable {X : C} variable (J J₂ : GrothendieckTopology C) /-- A presheaf is separated for a topology if it is separated for every sieve in the topology. -/ def IsSeparated (P : Cᵒᵖ ⥤ Type w) : Prop := ∀ ⦃X⦄ (S : Sieve X), S ∈ J X → IsSeparatedFor P (S : Presieve X) /-- A presheaf is a sheaf for a topology if it is a sheaf for every sieve in the topology. If the given topology is given by a pretopology, `isSheaf_pretopology` shows it suffices to check the sheaf condition at presieves in the pretopology. -/ def IsSheaf (P : Cᵒᵖ ⥤ Type w) : Prop := ∀ ⦃X⦄ (S : Sieve X), S ∈ J X → IsSheafFor P (S : Presieve X) theorem IsSheaf.isSheafFor {P : Cᵒᵖ ⥤ Type w} (hp : IsSheaf J P) (R : Presieve X) (hr : generate R ∈ J X) : IsSheafFor P R := (isSheafFor_iff_generate R).2 <| hp _ hr theorem isSheaf_of_le (P : Cᵒᵖ ⥤ Type w) {J₁ J₂ : GrothendieckTopology C} : J₁ ≤ J₂ → IsSheaf J₂ P → IsSheaf J₁ P := fun h t _ S hS => t S (h _ hS) theorem isSeparated_of_le (P : Cᵒᵖ ⥤ Type w) {J₁ J₂ : GrothendieckTopology C} : J₁ ≤ J₂ → IsSeparated J₂ P → IsSeparated J₁ P := fun h hP _ S hS ↦ hP S <| h _ hS variable {J} in theorem IsSheaf.isSeparated {P : Cᵒᵖ ⥤ Type w} (h : IsSheaf J P) : IsSeparated J P := fun _ S hS => (h S hS).isSeparatedFor @[deprecated (since := "2025-08-28")] alias isSeparated_of_isSheaf := IsSheaf.isSeparated variable {J} in /-- If `P` is separated and every compatible family of elements of `P` for a covering sieve has an amalgamation, `P` is a sheaf. -/ theorem IsSeparated.isSheaf {P : Cᵒᵖ ⥤ Type w} (h : IsSeparated J P) (h' : ∀ X, ∀ S ∈ J X, ∀ x : FamilyOfElements P S.arrows, x.Compatible → ∃ t, x.IsAmalgamation t) : IsSheaf J P := fun _ S hS ↦ (h S hS).isSheafFor <| h' _ S hS section variable {J} {P₁ : Cᵒᵖ ⥤ Type w} {P₂ : Cᵒᵖ ⥤ Type w'} (e : ∀ ⦃X : C⦄, P₁.obj (op X) ≃ P₂.obj (op X)) (he : ∀ ⦃X Y : C⦄ (f : X ⟶ Y) (x : P₁.obj (op Y)), e (P₁.map f.op x) = P₂.map f.op (e x)) include he in lemma isSheaf_of_nat_equiv (hP₁ : Presieve.IsSheaf J P₁) : Presieve.IsSheaf J P₂ := fun _ R hR ↦ isSheafFor_of_nat_equiv e he (hP₁ R hR) include he in lemma isSheaf_iff_of_nat_equiv : Presieve.IsSheaf J P₁ ↔ Presieve.IsSheaf J P₂ := ⟨fun hP₁ ↦ isSheaf_of_nat_equiv e he hP₁, fun hP₂ ↦ isSheaf_of_nat_equiv (fun _ ↦ (@e _).symm) (fun X Y f x ↦ by obtain ⟨y, rfl⟩ := e.surjective x refine e.injective ?_ simp only [Equiv.apply_symm_apply, Equiv.symm_apply_apply, he]) hP₂⟩ end /-- The property of being a sheaf is preserved by isomorphism. -/ theorem isSheaf_iso {P' : Cᵒᵖ ⥤ Type w} (i : P ≅ P') (h : IsSheaf J P) : IsSheaf J P' := fun _ S hS => isSheafFor_iso i (h S hS) /-- The property of being separated is preserved under isomorphisms. -/ theorem isSeparated_iso {P' : Cᵒᵖ ⥤ Type w} (i : P ≅ P') (hP : IsSeparated J P) : IsSeparated J P' := fun _ S hS ↦ isSeparatedFor_iso i (hP S hS) theorem isSheaf_of_yoneda {P : Cᵒᵖ ⥤ Type v} (h : ∀ {X} (S : Sieve X), S ∈ J X → YonedaSheafCondition P S) : IsSheaf J P := fun _ _ hS => isSheafFor_iff_yonedaSheafCondition.2 (h _ hS) /-- For a topology generated by a basis, it suffices to check the sheaf condition on the basis presieves only. -/ theorem isSheaf_pretopology [HasPullbacks C] (K : Pretopology C) : IsSheaf K.toGrothendieck P ↔ ∀ {X : C} (R : Presieve X), R ∈ K X → IsSheafFor P R := by constructor · intro PJ X R hR rw [isSheafFor_iff_generate] apply PJ (Sieve.generate R) ⟨_, hR, le_generate R⟩ · rintro PK X S ⟨R, hR, RS⟩ have gRS : ⇑(generate R) ≤ S := by apply giGenerate.gc.monotone_u rwa [generate_le_iff] apply isSheafFor_subsieve P gRS _ intro Y f rw [← pullbackArrows_comm, ← isSheafFor_iff_generate] exact PK (pullbackArrows f R) (K.pullbacks f R hR) /-- Any presheaf is a sheaf for the bottom (trivial) Grothendieck topology. -/ theorem isSheaf_bot : IsSheaf (⊥ : GrothendieckTopology C) P := fun X => by simp [isSheafFor_top_sieve] /-- The composition of a sheaf with a ULift functor is still a sheaf. -/ theorem isSheaf_comp_uliftFunctor (h : IsSheaf J P) : IsSheaf J (P ⋙ uliftFunctor.{w'}) := isSheaf_of_nat_equiv (fun _ => Equiv.ulift.symm) (fun _ _ _ _ => rfl) h /-- For a presheaf of the form `yoneda.obj W`, a compatible family of elements on a sieve is the same as a co-cone over the sieve. Constructing a co-cone from a compatible family works for any presieve, as does constructing a family of elements from a co-cone. Showing compatibility of the family needs the sieve condition. Note: This is related to `CategoryTheory.Presheaf.conesEquivSieveCompatibleFamily` -/ def compatibleYonedaFamily_toCocone (R : Presieve X) (W : C) (x : FamilyOfElements (yoneda.obj W) R) (hx : FamilyOfElements.Compatible x) : Cocone (R.diagram) where pt := W ι := { app := fun f => x f.obj.hom f.property naturality := by intro g₁ g₂ F simp only [Functor.id_obj, Functor.comp_obj, ObjectProperty.ι_obj, Over.forget_obj, Functor.const_obj_obj, Functor.comp_map, ObjectProperty.ι_map, Over.forget_map, Functor.const_obj_map, comp_id] rw [← Category.id_comp (x g₁.obj.hom g₁.property)] apply hx simp only [Functor.id_obj, Over.w, Opposite.unop_op, Category.id_comp] } /-- Construct a family of elements from a cocone. -/ def yonedaFamilyOfElements_fromCocone (R : Presieve X) (s : Cocone (diagram R)) : FamilyOfElements (yoneda.obj s.pt) R := fun _ f hf => s.ι.app ⟨Over.mk f, hf⟩ end Presieve namespace Sieve open Presieve variable {C : Type u} [Category.{v} C] variable {X : C} theorem yonedaFamily_fromCocone_compatible (S : Sieve X) (s : Cocone (diagram S.arrows)) : FamilyOfElements.Compatible <| yonedaFamilyOfElements_fromCocone S.arrows s := by intro Y₁ Y₂ Z g₁ g₂ f₁ f₂ hf₁ hf₂ hgf have Hs := s.ι.naturality simp only [Functor.id_obj, yoneda_obj_obj, Opposite.unop_op, yoneda_obj_map, Quiver.Hom.unop_op] dsimp [yonedaFamilyOfElements_fromCocone] have hgf₁ : S.arrows (g₁ ≫ f₁) := by exact Sieve.downward_closed S hf₁ g₁ have hgf₂ : S.arrows (g₂ ≫ f₂) := by exact Sieve.downward_closed S hf₂ g₂ let F : (Over.mk (g₁ ≫ f₁) : Over X) ⟶ (Over.mk (g₂ ≫ f₂) : Over X) := Over.homMk (𝟙 Z) let F₁ : (Over.mk (g₁ ≫ f₁) : Over X) ⟶ (Over.mk f₁ : Over X) := Over.homMk g₁ let F₂ : (Over.mk (g₂ ≫ f₂) : Over X) ⟶ (Over.mk f₂ : Over X) := Over.homMk g₂ have hF := @Hs ⟨Over.mk (g₁ ≫ f₁), hgf₁⟩ ⟨Over.mk (g₂ ≫ f₂), hgf₂⟩ F have hF₁ := @Hs ⟨Over.mk (g₁ ≫ f₁), hgf₁⟩ ⟨Over.mk f₁, hf₁⟩ F₁ have hF₂ := @Hs ⟨Over.mk (g₂ ≫ f₂), hgf₂⟩ ⟨Over.mk f₂, hf₂⟩ F₂ cat_disch /-- The base of a sieve `S` is a colimit of `S` iff all Yoneda-presheaves satisfy the sheaf condition for `S`. -/ theorem forallYonedaIsSheaf_iff_colimit (S : Sieve X) : (∀ W : C, Presieve.IsSheafFor (yoneda.obj W) (S : Presieve X)) ↔ Nonempty (IsColimit S.arrows.cocone) := by constructor · intro H refine Nonempty.intro ?_ exact { desc := fun s => H s.pt (yonedaFamilyOfElements_fromCocone S.arrows s) (yonedaFamily_fromCocone_compatible S s) |>.choose fac := by intro s f replace H := H s.pt (yonedaFamilyOfElements_fromCocone S.arrows s) (yonedaFamily_fromCocone_compatible S s) have ht := H.choose_spec.1 f.obj.hom f.property cat_disch uniq := by intro s Fs HFs replace H := H s.pt (yonedaFamilyOfElements_fromCocone S.arrows s) (yonedaFamily_fromCocone_compatible S s) apply H.choose_spec.2 Fs exact fun _ f hf => HFs ⟨Over.mk f, hf⟩ } · intro H W x hx replace H := Classical.choice H let s := compatibleYonedaFamily_toCocone S.arrows W x hx use H.desc s constructor · exact fun _ f hf => (H.fac s) ⟨Over.mk f, hf⟩ · exact fun g hg => H.uniq s g (fun ⟨⟨f, _, hom⟩, hf⟩ => hg hom hf) end Sieve end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/ChosenFiniteProducts.lean
import Mathlib.CategoryTheory.Sites.Limits import Mathlib.CategoryTheory.Monoidal.Cartesian.FunctorCategory deprecated_module (since := "2025-05-11")
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Spaces.lean
import Mathlib.CategoryTheory.Sites.Grothendieck import Mathlib.CategoryTheory.Sites.Pretopology import Mathlib.CategoryTheory.Limits.Lattice import Mathlib.Topology.Sets.Opens /-! # Grothendieck topology on a topological space Define the Grothendieck topology and the pretopology associated to a topological space, and show that the pretopology induces the topology. The covering (pre)sieves on `X` are those for which the union of domains contains `X`. ## Tags site, Grothendieck topology, space ## References * [nLab, *Grothendieck topology*](https://ncatlab.org/nlab/show/Grothendieck+topology) * [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92] ## Implementation notes We define the two separately, rather than defining the Grothendieck topology as that generated by the pretopology for the purpose of having nice definitional properties for the sieves. -/ universe u namespace Opens variable (T : Type u) [TopologicalSpace T] open CategoryTheory TopologicalSpace CategoryTheory.Limits /-- The Grothendieck topology associated to a topological space. -/ def grothendieckTopology : GrothendieckTopology (Opens T) where sieves X S := ∀ x ∈ X, ∃ (U : _) (f : U ⟶ X), S f ∧ x ∈ U top_mem' _ _ hx := ⟨_, 𝟙 _, trivial, hx⟩ pullback_stable' X Y S f hf y hy := by rcases hf y (f.le hy) with ⟨U, g, hg, hU⟩ refine ⟨U ⊓ Y, homOfLE inf_le_right, ?_, hU, hy⟩ apply S.downward_closed hg (homOfLE inf_le_left) transitive' X S hS R hR x hx := by rcases hS x hx with ⟨U, f, hf, hU⟩ rcases hR hf _ hU with ⟨V, g, hg, hV⟩ exact ⟨_, g ≫ f, hg, hV⟩ /-- The Grothendieck pretopology associated to a topological space. -/ def pretopology : Pretopology (Opens T) where coverings X R := ∀ x ∈ X, ∃ (U : _) (f : U ⟶ X), R f ∧ x ∈ U has_isos _ _ f _ _ hx := ⟨_, _, Presieve.singleton_self _, (inv f).le hx⟩ pullbacks X Y f S hS x hx := by rcases hS _ (f.le hx) with ⟨U, g, hg, hU⟩ refine ⟨_, _, Presieve.pullbackArrows.mk _ _ hg, ?_⟩ have : U ⊓ Y ≤ pullback g f := leOfHom (pullback.lift (homOfLE inf_le_left) (homOfLE inf_le_right) rfl) apply this ⟨hU, hx⟩ transitive X S Ti hS hTi x hx := by rcases hS x hx with ⟨U, f, hf, hU⟩ rcases hTi f hf x hU with ⟨V, g, hg, hV⟩ exact ⟨_, _, ⟨_, g, f, hf, hg, rfl⟩, hV⟩ /-- The pretopology associated to a space is the largest pretopology that generates the Grothendieck topology associated to the space. -/ @[simp] theorem toPretopology_grothendieckTopology : (Opens.grothendieckTopology T).toPretopology = Opens.pretopology T := by apply le_antisymm · intro X R hR x hx rcases hR x hx with ⟨U, f, ⟨V, g₁, g₂, hg₂, _⟩, hU⟩ exact ⟨V, g₂, hg₂, g₁.le hU⟩ · intro X R hR x hx rcases hR x hx with ⟨U, f, hf, hU⟩ exact ⟨U, f, Sieve.le_generate R U hf, hU⟩ @[deprecated (since := "2025-09-19")] alias pretopology_ofGrothendieck := toPretopology_grothendieckTopology /-- The pretopology associated to a space induces the Grothendieck topology associated to the space. -/ @[simp] theorem pretopology_toGrothendieck : (Opens.pretopology T).toGrothendieck = Opens.grothendieckTopology T := by rw [← toPretopology_grothendieckTopology] apply (Pretopology.gi (Opens T)).l_u_eq end Opens
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Sieves.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.Data.Set.BooleanAlgebra /-! # Theory of sieves - For an object `X` of a category `C`, a `Sieve X` is a set of morphisms to `X` which is closed under left-composition. - The complete lattice structure on sieves is given, as well as the Galois insertion given by downward-closing. - A `Sieve X` (functorially) induces a presheaf on `C` together with a monomorphism to the yoneda embedding of `X`. ## Tags sieve, pullback -/ universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory open Category Limits variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D) variable {X Y Z : C} (f : Y ⟶ X) /-- A set of arrows all with codomain `X`. -/ def Presieve (X : C) := ∀ ⦃Y⦄, Set (Y ⟶ X)-- deriving CompleteLattice instance : CompleteLattice (Presieve X) := by dsimp [Presieve] infer_instance namespace Presieve noncomputable instance : Inhabited (Presieve X) := ⟨⊤⟩ /-- The full subcategory of the over category `C/X` consisting of arrows which belong to a presieve on `X`. -/ abbrev category {X : C} (P : Presieve X) := ObjectProperty.FullSubcategory fun f : Over X => P f.hom /-- Construct an object of `P.category`. -/ abbrev categoryMk {X : C} (P : Presieve X) {Y : C} (f : Y ⟶ X) (hf : P f) : P.category := ⟨Over.mk f, hf⟩ /-- Given a sieve `S` on `X : C`, its associated diagram `S.diagram` is defined to be the natural functor from the full subcategory of the over category `C/X` consisting of arrows in `S` to `C`. -/ abbrev diagram (S : Presieve X) : S.category ⥤ C := ObjectProperty.ι _ ⋙ Over.forget X /-- Given a sieve `S` on `X : C`, its associated cocone `S.cocone` is defined to be the natural cocone over the diagram defined above with cocone point `X`. -/ abbrev cocone (S : Presieve X) : Cocone S.diagram := (Over.forgetCocone X).whisker (ObjectProperty.ι _) /-- Given a set of arrows `S` all with codomain `X`, and a set of arrows with codomain `Y` for each `f : Y ⟶ X` in `S`, produce a set of arrows with codomain `X`: `{ g ≫ f | (f : Y ⟶ X) ∈ S, (g : Z ⟶ Y) ∈ R f }`. -/ def bind (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y) : Presieve X := fun Z h => ∃ (Y : C) (g : Z ⟶ Y) (f : Y ⟶ X) (H : S f), R H g ∧ g ≫ f = h /-- Structure which contains the data and properties for a morphism `h` satisfying `Presieve.bind S R h`. -/ structure BindStruct (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y) {Z : C} (h : Z ⟶ X) where /-- the intermediate object -/ Y : C /-- a morphism in the family of presieves `R` -/ g : Z ⟶ Y /-- a morphism in the presieve `S` -/ f : Y ⟶ X hf : S f hg : R hf g fac : g ≫ f = h attribute [reassoc (attr := simp)] BindStruct.fac /-- If a morphism `h` satisfies `Presieve.bind S R h`, this is a choice of a structure in `BindStruct S R h`. -/ noncomputable def bind.bindStruct {S : Presieve X} {R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {Z : C} {h : Z ⟶ X} (H : bind S R h) : BindStruct S R h := Nonempty.some (by obtain ⟨Y, g, f, hf, hg, fac⟩ := H exact ⟨{ hf := hf, hg := hg, fac := fac, .. }⟩) lemma BindStruct.bind {S : Presieve X} {R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {Z : C} {h : Z ⟶ X} (b : BindStruct S R h) : bind S R h := ⟨b.Y, b.g, b.f, b.hf, b.hg, b.fac⟩ @[simp] theorem bind_comp {S : Presieve X} {R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {g : Z ⟶ Y} (h₁ : S f) (h₂ : R h₁ g) : bind S R (g ≫ f) := ⟨_, _, _, h₁, h₂, rfl⟩ -- Note we can't make this into `HasSingleton` because of the out-param. /-- The singleton presieve. -/ inductive singleton : Presieve X | mk : singleton f @[deprecated (since := "2025-08-22")] alias singleton' := singleton @[simp] theorem singleton_eq_iff_domain (f g : Y ⟶ X) : singleton f g ↔ f = g := by constructor · rintro ⟨a, rfl⟩ rfl · rintro rfl apply singleton.mk theorem singleton_self : singleton f f := singleton.mk /-- A presieve `R` has pullbacks along `f` if for every `h` in `R`, the pullback with `f` exists. -/ protected class HasPullbacks (R : Presieve X) {Y : C} (f : Y ⟶ X) : Prop where hasPullback (f) {Z : C} {h : Z ⟶ X} : R h → Limits.HasPullback h f protected alias hasPullback := HasPullbacks.hasPullback instance [HasPullbacks C] (R : Presieve X) {Y : C} (f : Y ⟶ X) : R.HasPullbacks f where hasPullback _ := inferInstance instance (g : Z ⟶ X) [HasPullback g f] : (singleton g).HasPullbacks f where hasPullback {Z} h := by intro ⟨⟩ infer_instance /-- Pullback a set of arrows with given codomain along a fixed map, by taking the pullback in the category. This is not the same as the arrow set of `Sieve.pullback`, but there is a relation between them in `pullbackArrows_comm`. -/ inductive pullbackArrows (R : Presieve X) [R.HasPullbacks f] : Presieve Y | mk (Z : C) (h : Z ⟶ X) (hRh : R h) : haveI := R.hasPullback f hRh pullbackArrows _ (pullback.snd h f) theorem pullback_singleton (g : Z ⟶ X) [HasPullback g f] : pullbackArrows f (singleton g) = singleton (pullback.snd g f) := by funext W ext h constructor · rintro ⟨W, _, _, _⟩ exact singleton.mk · rintro ⟨_⟩ exact pullbackArrows.mk Z g singleton.mk /-- Construct the presieve given by the family of arrows indexed by `ι`. -/ inductive ofArrows {ι : Type*} (Y : ι → C) (f : ∀ i, Y i ⟶ X) : Presieve X | mk (i : ι) : ofArrows _ _ (f i) lemma ofArrows.mk' {ι : Type*} {Y : ι → C} {f : ∀ i, Y i ⟶ X} {Z : C} {g : Z ⟶ X} (i : ι) (h : Z = Y i) (hg : g = eqToHom h ≫ f i) : ofArrows Y f g := by subst h simp only [eqToHom_refl, id_comp] at hg subst hg constructor theorem ofArrows_pUnit : (ofArrows _ fun _ : PUnit => f) = singleton f := by funext Y ext g constructor · rintro ⟨_⟩ apply singleton.mk · rintro ⟨_⟩ exact ofArrows.mk PUnit.unit instance {ι : Type*} (Z : ι → C) (g : ∀ i : ι, Z i ⟶ X) [∀ i, HasPullback (g i) f] : (ofArrows Z g).HasPullbacks f where hasPullback {_} _ := fun ⟨i⟩ ↦ inferInstance theorem ofArrows_pullback {ι : Type*} (Z : ι → C) (g : ∀ i : ι, Z i ⟶ X) [∀ i, HasPullback (g i) f] : (ofArrows (fun i => pullback (g i) f) fun _ => pullback.snd _ _) = pullbackArrows f (ofArrows Z g) := by funext T ext h constructor · rintro ⟨hk⟩ exact pullbackArrows.mk _ _ (ofArrows.mk hk) · rintro ⟨W, k, ⟨_⟩⟩ apply ofArrows.mk theorem ofArrows_bind {ι : Type*} (Z : ι → C) (g : ∀ i : ι, Z i ⟶ X) (j : ∀ ⦃Y⦄ (f : Y ⟶ X), ofArrows Z g f → Type*) (W : ∀ ⦃Y⦄ (f : Y ⟶ X) (H), j f H → C) (k : ∀ ⦃Y⦄ (f : Y ⟶ X) (H i), W f H i ⟶ Y) : ((ofArrows Z g).bind fun _ f H => ofArrows (W f H) (k f H)) = ofArrows (fun i : Σ i, j _ (ofArrows.mk i) => W (g i.1) _ i.2) fun ij => k (g ij.1) _ ij.2 ≫ g ij.1 := by funext Y ext f constructor · rintro ⟨_, _, _, ⟨i⟩, ⟨i'⟩, rfl⟩ exact ofArrows.mk (Sigma.mk _ _) · rintro ⟨i⟩ exact bind_comp _ (ofArrows.mk _) (ofArrows.mk _) theorem ofArrows_surj {ι : Type*} {Y : ι → C} (f : ∀ i, Y i ⟶ X) {Z : C} (g : Z ⟶ X) (hg : ofArrows Y f g) : ∃ (i : ι) (h : Y i = Z), g = eqToHom h.symm ≫ f i := by obtain ⟨i⟩ := hg exact ⟨i, rfl, by simp only [eqToHom_refl, id_comp]⟩ lemma exists_eq_ofArrows (R : Presieve X) : ∃ (ι : Type (max u₁ v₁)) (Y : ι → C) (f : ∀ i, Y i ⟶ X), R = .ofArrows Y f := by let ι := { x : Σ Z, (Z ⟶ X) // R x.2 } use ι, fun x ↦ x.1.1, fun x ↦ x.1.2 exact le_antisymm (fun Z g hg ↦ .mk (⟨⟨_, _⟩, hg⟩ : ι)) fun Z g ⟨x⟩ ↦ x.2 /-- If `g : Y ⟶ S` is in the presieve given by the indexed family `fᵢ`, this is a choice of index such that `g = fᵢ` modulo `eqToHom`. Note: This should generally not be used! If possible, use the induction principle for the type `Presieve.ofArrows` instead (using e.g., `rintro / obtain`). -/ noncomputable def ofArrows.idx {ι : Type*} {S : C} {X : ι → C} {f : ∀ i, X i ⟶ S} {Y : C} {g : Y ⟶ S} (hf : Presieve.ofArrows X f g) : ι := (ofArrows_surj _ _ hf).choose lemma ofArrows.obj_idx {ι : Type*} {S : C} {X : ι → C} {f : ∀ i, X i ⟶ S} {Y : C} {g : Y ⟶ S} (hf : ofArrows X f g) : X hf.idx = Y := (ofArrows_surj _ _ hf).choose_spec.1 lemma ofArrows.eq_eqToHom_comp_hom_idx {ι : Type*} {S : C} {X : ι → C} {f : ∀ i, X i ⟶ S} {Y : C} {g : Y ⟶ S} (hf : ofArrows X f g) : g = eqToHom hf.obj_idx.symm ≫ f hf.idx := (Presieve.ofArrows_surj _ _ hf).choose_spec.2 lemma ofArrows.hom_idx {ι : Type*} {S : C} {X : ι → C} {f : ∀ i, X i ⟶ S} {Y : C} {g : Y ⟶ S} (hf : ofArrows X f g) : f hf.idx = eqToHom hf.obj_idx ≫ g := by simp [eq_eqToHom_comp_hom_idx hf] /-- A convenient constructor for a refinement of a presieve of the form `Presieve.ofArrows`. This contains a sieve obtained by `Sieve.bind` and `Sieve.ofArrows`, see `Presieve.bind_ofArrows_le_bindOfArrows`, but has better definitional properties. -/ inductive bindOfArrows {ι : Type*} {X : C} (Y : ι → C) (f : ∀ i, Y i ⟶ X) (R : ∀ i, Presieve (Y i)) : Presieve X | mk (i : ι) {Z : C} (g : Z ⟶ Y i) (hg : R i g) : bindOfArrows Y f R (g ≫ f i) lemma bindOfArrows_ofArrows {ι : Type*} {S : C} {X : ι → C} (f : (i : ι) → X i ⟶ S) {σ : ι → Type*} {Y : (i : ι) → σ i → C} (g : (i : ι) → (j : σ i) → Y i j ⟶ X i) : Presieve.bindOfArrows X f (fun i ↦ .ofArrows (Y i) (g i)) = Presieve.ofArrows (fun p : Σ i, σ i ↦ Y p.1 p.2) (fun p ↦ g p.1 p.2 ≫ f p.1) := by refine le_antisymm ?_ (fun _ _ ⟨p⟩ ↦ ⟨p.1, _, ⟨p.2⟩⟩) rintro W u ⟨i, v, ⟨j⟩⟩ exact ⟨Sigma.mk i j⟩ /-- Given a presieve on `F(X)`, we can define a presieve on `X` by taking the preimage via `F`. -/ def functorPullback (R : Presieve (F.obj X)) : Presieve X := fun _ f => R (F.map f) @[simp] theorem functorPullback_mem (R : Presieve (F.obj X)) {Y} (f : Y ⟶ X) : R.functorPullback F f ↔ R (F.map f) := Iff.rfl @[simp] theorem functorPullback_id (R : Presieve X) : R.functorPullback (𝟭 _) = R := rfl /-- Given a presieve `R` on `X`, the predicate `R.HasPairwisePullbacks` means that for all arrows `f` and `g` in `R`, the pullback of `f` and `g` exists. -/ class HasPairwisePullbacks (R : Presieve X) : Prop where /-- For all arrows `f` and `g` in `R`, the pullback of `f` and `g` exists. -/ has_pullbacks : ∀ {Y Z} {f : Y ⟶ X} (_ : R f) {g : Z ⟶ X} (_ : R g), HasPullback f g @[deprecated (since := "2025-08-28")] alias hasPullbacks := HasPairwisePullbacks instance (R : Presieve X) [HasPullbacks C] : R.HasPairwisePullbacks := ⟨fun _ _ ↦ inferInstance⟩ instance {α : Type v₂} {X : α → C} {B : C} (π : (a : α) → X a ⟶ B) [(Presieve.ofArrows X π).HasPairwisePullbacks] (a b : α) : HasPullback (π a) (π b) := Presieve.HasPairwisePullbacks.has_pullbacks (Presieve.ofArrows.mk _) (Presieve.ofArrows.mk _) section FunctorPushforward variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E) /-- Given a presieve on `X`, we can define a presieve on `F(X)` (which is actually a sieve) by taking the sieve generated by the image via `F`. -/ def functorPushforward (S : Presieve X) : Presieve (F.obj X) := fun Y f => ∃ (Z : C) (g : Z ⟶ X) (h : Y ⟶ F.obj Z), S g ∧ f = h ≫ F.map g /-- An auxiliary definition in order to fix the choice of the preimages between various definitions. -/ structure FunctorPushforwardStructure (S : Presieve X) {Y} (f : Y ⟶ F.obj X) where /-- an object in the source category -/ preobj : C /-- a map in the source category which has to be in the presieve -/ premap : preobj ⟶ X /-- the morphism which appear in the factorisation -/ lift : Y ⟶ F.obj preobj /-- the condition that `premap` is in the presieve -/ cover : S premap /-- the factorisation of the morphism -/ fac : f = lift ≫ F.map premap /-- The fixed choice of a preimage. -/ noncomputable def getFunctorPushforwardStructure {F : C ⥤ D} {S : Presieve X} {Y : D} {f : Y ⟶ F.obj X} (h : S.functorPushforward F f) : FunctorPushforwardStructure F S f := by choose Z f' g h₁ h using h exact ⟨Z, f', g, h₁, h⟩ theorem functorPushforward_comp (R : Presieve X) : R.functorPushforward (F ⋙ G) = (R.functorPushforward F).functorPushforward G := by funext x ext f constructor · rintro ⟨X, f₁, g₁, h₁, rfl⟩ exact ⟨F.obj X, F.map f₁, g₁, ⟨X, f₁, 𝟙 _, h₁, by simp⟩, rfl⟩ · rintro ⟨X, f₁, g₁, ⟨X', f₂, g₂, h₁, rfl⟩, rfl⟩ exact ⟨X', f₂, g₁ ≫ G.map g₂, h₁, by simp⟩ theorem image_mem_functorPushforward (R : Presieve X) {f : Y ⟶ X} (h : R f) : R.functorPushforward F (F.map f) := ⟨Y, f, 𝟙 _, h, by simp⟩ /-- This presieve generates `functorPushforward`. See `arrows_generate_map_eq_functorPushforward`. -/ inductive map (s : Presieve X) : Presieve (F.obj X) where | of {Y : C} {u : Y ⟶ X} (h : s u) : map s (F.map u) section variable {F} @[grind ←] lemma map_map {X Y : C} {f : Y ⟶ X} {R : Presieve X} (hf : R f) : R.map F (F.map f) := ⟨hf⟩ @[simp] lemma map_ofArrows {X : C} {ι : Type*} {Y : ι → C} (f : ∀ i, Y i ⟶ X) : (ofArrows Y f).map F = ofArrows _ (fun i ↦ F.map (f i)) := by refine le_antisymm (fun Z g hg ↦ ?_) fun _ _ ⟨i⟩ ↦ map_map ⟨i⟩ obtain ⟨hu⟩ := hg obtain ⟨i, rfl, rfl⟩ := Presieve.ofArrows_surj _ _ hu simpa using ofArrows.mk i @[simp] lemma map_singleton {X Y : C} (f : X ⟶ Y) : (singleton f).map F = singleton (F.map f) := by rw [← ofArrows_pUnit.{_, _, 0}, map_ofArrows, ofArrows_pUnit] lemma map_functorPullback {X : C} (R : Presieve (F.obj X)) : (R.functorPullback F).map F ≤ R := fun _ _ ⟨hu⟩ ↦ hu @[simp] lemma map_id {X : C} (R : Presieve X) : R.map (𝟭 C) = R := le_antisymm (fun _ _ ⟨hg⟩ ↦ hg) fun _ _ hg ↦ ⟨hg⟩ lemma map_monotone {R S : Presieve X} (h : R ≤ S) : R.map F ≤ S.map F := fun _ _ ⟨hf⟩ ↦ ⟨h _ hf⟩ end end FunctorPushforward section uncurry variable (s : Presieve X) /-- Uncurry a presieve to one set over the sigma type. -/ def uncurry : Set (Σ Y, Y ⟶ X) := { u | s u.snd } @[simp] theorem uncurry_singleton {Y : C} (u : Y ⟶ X) : (singleton u).uncurry = { ⟨Y, u⟩ } := by ext ⟨Z, v⟩; constructor · rintro ⟨⟩; rfl · intro h rw [Set.mem_singleton_iff, Sigma.ext_iff] at h obtain ⟨rfl, h⟩ := h; subst h; constructor @[simp] theorem uncurry_pullbackArrows [HasPullbacks C] {B : C} (b : B ⟶ X) : (pullbackArrows b s).uncurry = (fun f ↦ ⟨pullback f.2 b, pullback.snd _ _⟩) '' s.uncurry := by ext ⟨Z, v⟩; constructor · rintro ⟨Y, u, hu⟩; exact ⟨⟨Y, u⟩, hu, rfl⟩ · rintro ⟨⟨Y, u⟩, hu, h⟩ rw [Sigma.ext_iff] at h obtain ⟨rfl, h⟩ := h rw [heq_iff_eq] at h; subst h exact ⟨Y, u, hu⟩ @[simp] theorem uncurry_bind (t : ⦃Y : C⦄ → (f : Y ⟶ X) → s f → Presieve Y) : (s.bind t).uncurry = ⋃ i ∈ s.uncurry, Sigma.map id (fun Z g ↦ (g ≫ i.2 : Z ⟶ X)) '' (t _ ‹_›).uncurry := by ext ⟨Z, v⟩; simp only [Set.mem_iUnion, Set.mem_image]; constructor · rintro ⟨Y, g, f, hf, ht, hv⟩ exact ⟨⟨_, f⟩, hf, ⟨_, g⟩, ht, Sigma.ext rfl (heq_of_eq hv)⟩ · rintro ⟨⟨_, f⟩, hf, ⟨Y, g⟩, hg, h⟩ rw [Sigma.ext_iff] at h obtain ⟨rfl, h⟩ := h rw [heq_iff_eq] at h; subst h exact ⟨_, _, _, _, hg, rfl⟩ @[simp] theorem uncurry_ofArrows {ι : Type*} (Y : ι → C) (f : (i : ι) → Y i ⟶ X) : (ofArrows Y f).uncurry = Set.range fun i : ι ↦ ⟨_, f i⟩ := by ext ⟨Z, v⟩; simp only [Set.mem_range, Sigma.mk.injEq]; constructor · rintro ⟨i⟩; exact ⟨_, rfl, HEq.refl _⟩ · rintro ⟨i, rfl, h⟩; rw [← eq_of_heq h]; exact ⟨i⟩ lemma ofArrows_eq_ofArrows_uncurry {ι : Type*} {S : C} {X : ι → C} (f : ∀ i, X i ⟶ S) : ofArrows X f = ofArrows _ (fun i : (Presieve.ofArrows X f).uncurry ↦ f i.2.idx) := by refine le_antisymm (fun Z g hg ↦ ?_) fun Z g ⟨i⟩ ↦ .mk _ exact .mk' ⟨⟨_, _⟩, hg⟩ (by simp [ofArrows.obj_idx]) (by simp [ofArrows.hom_idx]) end uncurry end Presieve /-- For an object `X` of a category `C`, a `Sieve X` is a set of morphisms to `X` which is closed under left-composition. -/ structure Sieve {C : Type u₁} [Category.{v₁} C] (X : C) where /-- the underlying presieve -/ arrows : Presieve X /-- stability by precomposition -/ downward_closed : ∀ {Y Z f} (_ : arrows f) (g : Z ⟶ Y), arrows (g ≫ f) namespace Sieve instance : CoeFun (Sieve X) fun _ => Presieve X := ⟨Sieve.arrows⟩ initialize_simps_projections Sieve (arrows → apply) variable {S R : Sieve X} attribute [simp] downward_closed theorem arrows_ext : ∀ {R S : Sieve X}, R.arrows = S.arrows → R = S := by rintro ⟨_, _⟩ ⟨_, _⟩ rfl rfl @[ext] protected theorem ext {R S : Sieve X} (h : ∀ ⦃Y⦄ (f : Y ⟶ X), R f ↔ S f) : R = S := arrows_ext <| funext fun _ => funext fun f => propext <| h f open Lattice /-- The supremum of a collection of sieves: the union of them all. -/ protected def sup (𝒮 : Set (Sieve X)) : Sieve X where arrows _ := { f | ∃ S ∈ 𝒮, Sieve.arrows S f } downward_closed {_ _ f} hf _ := by obtain ⟨S, hS, hf⟩ := hf exact ⟨S, hS, S.downward_closed hf _⟩ /-- The infimum of a collection of sieves: the intersection of them all. -/ protected def inf (𝒮 : Set (Sieve X)) : Sieve X where arrows _ := { f | ∀ S ∈ 𝒮, Sieve.arrows S f } downward_closed {_ _ _} hf g S H := S.downward_closed (hf S H) g /-- The union of two sieves is a sieve. -/ protected def union (S R : Sieve X) : Sieve X where arrows _ f := S f ∨ R f downward_closed := by rintro _ _ _ (h | h) g <;> simp [h] /-- The intersection of two sieves is a sieve. -/ protected def inter (S R : Sieve X) : Sieve X where arrows _ f := S f ∧ R f downward_closed := by rintro _ _ _ ⟨h₁, h₂⟩ g simp [h₁, h₂] /-- Sieves on an object `X` form a complete lattice. We generate this directly rather than using the Galois insertion for nicer definitional properties. -/ instance : CompleteLattice (Sieve X) where le S R := ∀ ⦃Y⦄ (f : Y ⟶ X), S f → R f le_refl _ _ _ := id le_trans _ _ _ S₁₂ S₂₃ _ _ h := S₂₃ _ (S₁₂ _ h) le_antisymm _ _ p q := Sieve.ext fun _ _ => ⟨p _, q _⟩ top := { arrows := fun _ => Set.univ downward_closed := fun _ _ => ⟨⟩ } bot := { arrows := fun _ => ∅ downward_closed := False.elim } sup := Sieve.union inf := Sieve.inter sSup := Sieve.sup sInf := Sieve.inf le_sSup _ S hS _ _ hf := ⟨S, hS, hf⟩ sSup_le := fun _ _ ha _ _ ⟨b, hb, hf⟩ => (ha b hb) _ hf sInf_le _ _ hS _ _ h := h _ hS le_sInf _ _ hS _ _ hf _ hR := hS _ hR _ hf le_sup_left _ _ _ _ := Or.inl le_sup_right _ _ _ _ := Or.inr sup_le _ _ _ h₁ h₂ _ f := by--ℰ S hS Y f := by rintro (hf | hf) · exact h₁ _ hf · exact h₂ _ hf inf_le_left _ _ _ _ := And.left inf_le_right _ _ _ _ := And.right le_inf _ _ _ p q _ _ z := ⟨p _ z, q _ z⟩ le_top _ _ _ _ := trivial bot_le _ _ _ := False.elim /-- The maximal sieve always exists. -/ instance sieveInhabited : Inhabited (Sieve X) := ⟨⊤⟩ @[simp] theorem sInf_apply {Ss : Set (Sieve X)} {Y} (f : Y ⟶ X) : sInf Ss f ↔ ∀ (S : Sieve X) (_ : S ∈ Ss), S f := Iff.rfl @[simp] theorem sSup_apply {Ss : Set (Sieve X)} {Y} (f : Y ⟶ X) : sSup Ss f ↔ ∃ (S : Sieve X) (_ : S ∈ Ss), S f := by simp [sSup, Sieve.sup, setOf] @[simp] theorem inter_apply {R S : Sieve X} {Y} (f : Y ⟶ X) : (R ⊓ S) f ↔ R f ∧ S f := Iff.rfl @[simp] theorem union_apply {R S : Sieve X} {Y} (f : Y ⟶ X) : (R ⊔ S) f ↔ R f ∨ S f := Iff.rfl @[simp] theorem top_apply (f : Y ⟶ X) : (⊤ : Sieve X) f := trivial /-- Generate the smallest sieve containing the given set of arrows. -/ @[simps] def generate (R : Presieve X) : Sieve X where arrows Z f := ∃ (Y : _) (h : Z ⟶ Y) (g : Y ⟶ X), R g ∧ h ≫ g = f downward_closed := by rintro Y Z _ ⟨W, g, f, hf, rfl⟩ h exact ⟨_, h ≫ g, _, hf, by simp⟩ theorem arrows_generate_map_eq_functorPushforward {s : Presieve X} : (generate (s.map F)).arrows = s.functorPushforward F := by refine funext fun Z ↦ Set.ext fun u ↦ ⟨?_, ?_⟩ · rintro ⟨_, _, _, ⟨hu⟩, rfl⟩; exact ⟨_, _, _, hu, rfl⟩ · rintro ⟨_, _, _, hu, rfl⟩; exact ⟨_, _, _, ⟨hu⟩, rfl⟩ /-- Given a presieve on `X`, and a sieve on each domain of an arrow in the presieve, we can bind to produce a sieve on `X`. -/ @[simps] def bind (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) : Sieve X where arrows := S.bind fun _ _ h => R h downward_closed := by rintro Y Z f ⟨W, f, h, hh, hf, rfl⟩ g exact ⟨_, g ≫ f, _, hh, by simp [hf]⟩ /-- Structure which contains the data and properties for a morphism `h` satisfying `Sieve.bind S R h`. -/ abbrev BindStruct (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) {Z : C} (h : Z ⟶ X) := Presieve.BindStruct S (fun _ _ hf ↦ R hf) h open Order Lattice theorem generate_le_iff (R : Presieve X) (S : Sieve X) : generate R ≤ S ↔ R ≤ S := ⟨fun H _ _ hg => H _ ⟨_, 𝟙 _, _, hg, id_comp _⟩, fun ss Y f => by rintro ⟨Z, f, g, hg, rfl⟩ exact S.downward_closed (ss Z hg) f⟩ /-- Show that there is a Galois insertion (generate, set_over). -/ def giGenerate : GaloisInsertion (generate : Presieve X → Sieve X) arrows where gc := generate_le_iff choice 𝒢 _ := generate 𝒢 choice_eq _ _ := rfl le_l_u _ _ _ hf := ⟨_, 𝟙 _, _, hf, id_comp _⟩ theorem le_generate (R : Presieve X) : R ≤ generate R := giGenerate.gc.le_u_l R @[simp] theorem generate_sieve (S : Sieve X) : generate S = S := giGenerate.l_u_eq S /-- If the identity arrow is in a sieve, the sieve is maximal. -/ theorem id_mem_iff_eq_top : S (𝟙 X) ↔ S = ⊤ := ⟨fun h => top_unique fun Y f _ => by simpa using downward_closed _ h f, fun h => h.symm ▸ trivial⟩ /-- If an arrow set contains a split epi, it generates the maximal sieve. -/ theorem generate_of_contains_isSplitEpi {R : Presieve X} (f : Y ⟶ X) [IsSplitEpi f] (hf : R f) : generate R = ⊤ := by rw [← id_mem_iff_eq_top] exact ⟨_, section_ f, f, hf, by simp⟩ @[simp] theorem generate_of_singleton_isSplitEpi (f : Y ⟶ X) [IsSplitEpi f] : generate (Presieve.singleton f) = ⊤ := generate_of_contains_isSplitEpi f (Presieve.singleton_self _) @[simp] theorem generate_top : generate (⊤ : Presieve X) = ⊤ := generate_of_contains_isSplitEpi (𝟙 _) ⟨⟩ @[simp] lemma comp_mem_iff (i : X ⟶ Y) (f : Y ⟶ Z) [IsIso i] (S : Sieve Z) : S (i ≫ f) ↔ S f := by refine ⟨fun H ↦ ?_, fun H ↦ S.downward_closed H _⟩ convert S.downward_closed H (inv i) simp section variable {I : Type*} {X : C} (Y : I → C) (f : ∀ i, Y i ⟶ X) /-- The sieve of `X` generated by family of morphisms `Y i ⟶ X`. -/ abbrev ofArrows : Sieve X := generate (Presieve.ofArrows Y f) lemma ofArrows_mk (i : I) : ofArrows Y f (f i) := ⟨_, 𝟙 _, _, ⟨i⟩, by simp⟩ lemma mem_ofArrows_iff {W : C} (g : W ⟶ X) : ofArrows Y f g ↔ ∃ (i : I) (a : W ⟶ Y i), g = a ≫ f i := by constructor · rintro ⟨T, a, b, ⟨i⟩, rfl⟩ exact ⟨i, a, rfl⟩ · rintro ⟨i, a, rfl⟩ apply downward_closed _ (ofArrows_mk Y f i) variable {Y f} {W : C} {g : W ⟶ X} (hg : ofArrows Y f g) include hg in lemma ofArrows.exists : ∃ (i : I) (h : W ⟶ Y i), g = h ≫ f i := by obtain ⟨_, h, _, ⟨i⟩, rfl⟩ := hg exact ⟨i, h, rfl⟩ /-- When `hg : Sieve.ofArrows Y f g`, this is a choice of `i` such that `g` factors through `f i`. -/ noncomputable def ofArrows.i : I := (ofArrows.exists hg).choose /-- When `hg : Sieve.ofArrows Y f g`, this is a morphism `h : W ⟶ Y (i hg)` such that `h ≫ f (i hg) = g`. -/ noncomputable def ofArrows.h : W ⟶ Y (i hg) := (ofArrows.exists hg).choose_spec.choose @[reassoc (attr := simp)] lemma ofArrows.fac : h hg ≫ f (i hg) = g := (ofArrows.exists hg).choose_spec.choose_spec.symm end /-- The sieve generated by two morphisms. -/ abbrev ofTwoArrows {U V X : C} (i : U ⟶ X) (j : V ⟶ X) : Sieve X := Sieve.ofArrows (Y := pairFunction U V) (fun k ↦ WalkingPair.casesOn k i j) /-- The sieve of `X : C` that is generated by a family of objects `Y : I → C`: it consists of morphisms to `X` which factor through at least one of the `Y i`. -/ def ofObjects {I : Type*} (Y : I → C) (X : C) : Sieve X where arrows Z _ := ∃ (i : I), Nonempty (Z ⟶ Y i) downward_closed := by rintro Z₁ Z₂ p ⟨i, ⟨f⟩⟩ g exact ⟨i, ⟨g ≫ f⟩⟩ lemma mem_ofObjects_iff {I : Type*} (Y : I → C) {Z X : C} (g : Z ⟶ X) : ofObjects Y X g ↔ ∃ (i : I), Nonempty (Z ⟶ Y i) := by rfl lemma ofArrows_le_ofObjects {I : Type*} (Y : I → C) {X : C} (f : ∀ i, Y i ⟶ X) : Sieve.ofArrows Y f ≤ Sieve.ofObjects Y X := by intro W g hg rw [mem_ofArrows_iff] at hg obtain ⟨i, a, rfl⟩ := hg exact ⟨i, ⟨a⟩⟩ lemma ofArrows_eq_ofObjects {X : C} (hX : IsTerminal X) {I : Type*} (Y : I → C) (f : ∀ i, Y i ⟶ X) : ofArrows Y f = ofObjects Y X := by refine le_antisymm (ofArrows_le_ofObjects Y f) (fun W g => ?_) rw [mem_ofArrows_iff, mem_ofObjects_iff] rintro ⟨i, ⟨h⟩⟩ exact ⟨i, h, hX.hom_ext _ _⟩ /-- Given a morphism `h : Y ⟶ X`, send a sieve S on X to a sieve on Y as the inverse image of S with `_ ≫ h`. That is, `Sieve.pullback S h := (≫ h) '⁻¹ S`. -/ @[simps] def pullback (h : Y ⟶ X) (S : Sieve X) : Sieve Y where arrows _ sl := S (sl ≫ h) downward_closed g := by simp [g] @[simp] theorem pullback_id : S.pullback (𝟙 _) = S := by simp [Sieve.ext_iff] @[simp] theorem pullback_top {f : Y ⟶ X} : (⊤ : Sieve X).pullback f = ⊤ := top_unique fun _ _ => id theorem pullback_comp {f : Y ⟶ X} {g : Z ⟶ Y} (S : Sieve X) : S.pullback (g ≫ f) = (S.pullback f).pullback g := by simp [Sieve.ext_iff] @[simp] theorem pullback_inter {f : Y ⟶ X} (S R : Sieve X) : (S ⊓ R).pullback f = S.pullback f ⊓ R.pullback f := by simp [Sieve.ext_iff] theorem mem_iff_pullback_eq_top (f : Y ⟶ X) : S f ↔ S.pullback f = ⊤ := by rw [← id_mem_iff_eq_top, pullback_apply, id_comp] theorem pullback_eq_top_of_mem (S : Sieve X) {f : Y ⟶ X} : S f → S.pullback f = ⊤ := (mem_iff_pullback_eq_top f).1 lemma pullback_ofObjects_eq_top {I : Type*} (Y : I → C) {X : C} {i : I} (g : X ⟶ Y i) : ofObjects Y X = ⊤ := by ext Z h simp only [top_apply, iff_true] rw [mem_ofObjects_iff ] exact ⟨i, ⟨h ≫ g⟩⟩ /-- Push a sieve `R` on `Y` forward along an arrow `f : Y ⟶ X`: `gf : Z ⟶ X` is in the sieve if `gf` factors through some `g : Z ⟶ Y` which is in `R`. -/ @[simps] def pushforward (f : Y ⟶ X) (R : Sieve Y) : Sieve X where arrows _ gf := ∃ g, g ≫ f = gf ∧ R g downward_closed := fun ⟨j, k, z⟩ h => ⟨h ≫ j, by simp [k], by simp [z]⟩ theorem pushforward_apply_comp {R : Sieve Y} {Z : C} {g : Z ⟶ Y} (hg : R g) (f : Y ⟶ X) : R.pushforward f (g ≫ f) := ⟨g, rfl, hg⟩ theorem pushforward_comp {f : Y ⟶ X} {g : Z ⟶ Y} (R : Sieve Z) : R.pushforward (g ≫ f) = (R.pushforward g).pushforward f := Sieve.ext fun W h => ⟨fun ⟨f₁, hq, hf₁⟩ => ⟨f₁ ≫ g, by simpa, f₁, rfl, hf₁⟩, fun ⟨y, hy, z, hR, hz⟩ => ⟨z, by rw [← Category.assoc, hR]; tauto⟩⟩ theorem galoisConnection (f : Y ⟶ X) : GaloisConnection (Sieve.pushforward f) (Sieve.pullback f) := fun _ _ => ⟨fun hR _ g hg => hR _ ⟨g, rfl, hg⟩, fun hS _ _ ⟨h, hg, hh⟩ => hg ▸ hS h hh⟩ theorem pullback_monotone (f : Y ⟶ X) : Monotone (Sieve.pullback f) := (galoisConnection f).monotone_u theorem pushforward_monotone (f : Y ⟶ X) : Monotone (Sieve.pushforward f) := (galoisConnection f).monotone_l theorem le_pushforward_pullback (f : Y ⟶ X) (R : Sieve Y) : R ≤ (R.pushforward f).pullback f := (galoisConnection f).le_u_l _ theorem pullback_pushforward_le (f : Y ⟶ X) (R : Sieve X) : (R.pullback f).pushforward f ≤ R := (galoisConnection f).l_u_le _ theorem pushforward_union {f : Y ⟶ X} (S R : Sieve Y) : (S ⊔ R).pushforward f = S.pushforward f ⊔ R.pushforward f := (galoisConnection f).l_sup theorem pushforward_le_bind_of_mem (S : Presieve X) (R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) (f : Y ⟶ X) (h : S f) : (R h).pushforward f ≤ bind S R := by rintro Z _ ⟨g, rfl, hg⟩ exact ⟨_, g, f, h, hg, rfl⟩ theorem le_pullback_bind (S : Presieve X) (R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) (f : Y ⟶ X) (h : S f) : R h ≤ (bind S R).pullback f := by rw [← galoisConnection f] apply pushforward_le_bind_of_mem /-- If `f` is a monomorphism, the pushforward-pullback adjunction on sieves is coreflective. -/ def galoisCoinsertionOfMono (f : Y ⟶ X) [Mono f] : GaloisCoinsertion (Sieve.pushforward f) (Sieve.pullback f) := by apply (galoisConnection f).toGaloisCoinsertion rintro S Z g ⟨g₁, hf, hg₁⟩ rw [cancel_mono f] at hf rwa [← hf] /-- If `f` is a split epi, the pushforward-pullback adjunction on sieves is reflective. -/ def galoisInsertionOfIsSplitEpi (f : Y ⟶ X) [IsSplitEpi f] : GaloisInsertion (Sieve.pushforward f) (Sieve.pullback f) := by apply (galoisConnection f).toGaloisInsertion intro S Z g hg exact ⟨g ≫ section_ f, by simpa⟩ theorem pullbackArrows_comm {X Y : C} (f : Y ⟶ X) (R : Presieve X) [R.HasPullbacks f] : Sieve.generate (R.pullbackArrows f) = (Sieve.generate R).pullback f := by ext W g constructor · rintro ⟨_, h, k, ⟨W, g, hg⟩, rfl⟩ have := R.hasPullback f hg rw [Sieve.pullback_apply, assoc, ← pullback.condition, ← assoc] exact Sieve.downward_closed _ (by exact Sieve.le_generate R W hg) (h ≫ pullback.fst g f) · rintro ⟨W, h, k, hk, comm⟩ have := R.hasPullback f hk exact ⟨_, _, _, Presieve.pullbackArrows.mk _ _ hk, pullback.lift_snd _ _ comm⟩ section Functor variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E) /-- If `R` is a sieve, then the `CategoryTheory.Presieve.functorPullback` of `R` is actually a sieve. -/ @[simps] def functorPullback (R : Sieve (F.obj X)) : Sieve X where arrows := Presieve.functorPullback F R downward_closed := by intro _ _ f hf g unfold Presieve.functorPullback rw [F.map_comp] exact R.downward_closed hf (F.map g) @[simp] theorem functorPullback_arrows (R : Sieve (F.obj X)) : (R.functorPullback F).arrows = R.arrows.functorPullback F := rfl @[simp] theorem functorPullback_id (R : Sieve X) : R.functorPullback (𝟭 _) = R := by ext rfl theorem functorPullback_comp (R : Sieve ((F ⋙ G).obj X)) : R.functorPullback (F ⋙ G) = (R.functorPullback G).functorPullback F := by ext rfl lemma generate_functorPullback_le {X : C} (R : Presieve (F.obj X)) : generate (R.functorPullback F) ≤ functorPullback F (generate R) := by rw [generate_le_iff] intro Z g hg exact le_generate _ _ hg lemma functorPullback_pullback {X Y : C} (f : X ⟶ Y) (S : Sieve (F.obj Y)) : functorPullback F (pullback (F.map f) S) = pullback f (functorPullback F S) := by ext simp theorem functorPushforward_extend_eq {R : Presieve X} : (generate R).arrows.functorPushforward F = R.functorPushforward F := by funext Y ext f constructor · rintro ⟨X', g, f', ⟨X'', g', f'', h₁, rfl⟩, rfl⟩ exact ⟨X'', f'', f' ≫ F.map g', h₁, by simp⟩ · rintro ⟨X', g, f', h₁, h₂⟩ exact ⟨X', g, f', le_generate R _ h₁, h₂⟩ /-- The sieve generated by the image of `R` under `F`. -/ @[simps] def functorPushforward (R : Sieve X) : Sieve (F.obj X) where arrows := R.arrows.functorPushforward F downward_closed := by intro _ _ f h g obtain ⟨X, α, β, hα, rfl⟩ := h exact ⟨X, α, g ≫ β, hα, by simp⟩ theorem generate_map_eq_functorPushforward {s : Presieve X} : generate (s.map F) = (generate s).functorPushforward F := by ext rw [arrows_generate_map_eq_functorPushforward] simp [functorPushforward_extend_eq] @[simp] theorem functorPushforward_id (R : Sieve X) : R.functorPushforward (𝟭 _) = R := by ext X f constructor · intro hf obtain ⟨X, g, h, hg, rfl⟩ := hf exact R.downward_closed hg h · intro hf exact ⟨X, f, 𝟙 _, hf, by simp⟩ theorem functorPushforward_comp (R : Sieve X) : R.functorPushforward (F ⋙ G) = (R.functorPushforward F).functorPushforward G := by ext simp [R.arrows.functorPushforward_comp F G] theorem functor_galoisConnection (X : C) : GaloisConnection (Sieve.functorPushforward F : Sieve X → Sieve (F.obj X)) (Sieve.functorPullback F) := by intro R S constructor · intro hle X f hf apply hle refine ⟨X, f, 𝟙 _, hf, ?_⟩ rw [id_comp] · rintro hle Y f ⟨X, g, h, hg, rfl⟩ apply Sieve.downward_closed S exact hle g hg theorem functorPullback_monotone (X : C) : Monotone (Sieve.functorPullback F : Sieve (F.obj X) → Sieve X) := (functor_galoisConnection F X).monotone_u theorem functorPushforward_monotone (X : C) : Monotone (Sieve.functorPushforward F : Sieve X → Sieve (F.obj X)) := (functor_galoisConnection F X).monotone_l theorem le_functorPushforward_pullback (R : Sieve X) : R ≤ (R.functorPushforward F).functorPullback F := (functor_galoisConnection F X).le_u_l _ theorem functorPullback_pushforward_le (R : Sieve (F.obj X)) : (R.functorPullback F).functorPushforward F ≤ R := (functor_galoisConnection F X).l_u_le _ theorem functorPushforward_union (S R : Sieve X) : (S ⊔ R).functorPushforward F = S.functorPushforward F ⊔ R.functorPushforward F := (functor_galoisConnection F X).l_sup theorem functorPullback_union (S R : Sieve (F.obj X)) : (S ⊔ R).functorPullback F = S.functorPullback F ⊔ R.functorPullback F := rfl theorem functorPullback_inter (S R : Sieve (F.obj X)) : (S ⊓ R).functorPullback F = S.functorPullback F ⊓ R.functorPullback F := rfl @[simp] theorem functorPushforward_bot (F : C ⥤ D) (X : C) : (⊥ : Sieve X).functorPushforward F = ⊥ := (functor_galoisConnection F X).l_bot @[simp] theorem functorPushforward_top (F : C ⥤ D) (X : C) : (⊤ : Sieve X).functorPushforward F = ⊤ := by refine (generate_sieve _).symm.trans ?_ apply generate_of_contains_isSplitEpi (𝟙 (F.obj X)) exact ⟨X, 𝟙 _, 𝟙 _, trivial, by simp⟩ @[simp] theorem functorPullback_bot (F : C ⥤ D) (X : C) : (⊥ : Sieve (F.obj X)).functorPullback F = ⊥ := rfl @[simp] theorem functorPullback_top (F : C ⥤ D) (X : C) : (⊤ : Sieve (F.obj X)).functorPullback F = ⊤ := rfl theorem image_mem_functorPushforward (R : Sieve X) {V} {f : V ⟶ X} (h : R f) : R.functorPushforward F (F.map f) := ⟨V, f, 𝟙 _, h, by simp⟩ /-- When `F` is essentially surjective and full, the Galois connection is a Galois insertion. -/ def essSurjFullFunctorGaloisInsertion [F.EssSurj] [F.Full] (X : C) : GaloisInsertion (Sieve.functorPushforward F : Sieve X → Sieve (F.obj X)) (Sieve.functorPullback F) := by apply (functor_galoisConnection F X).toGaloisInsertion intro S Y f hf refine ⟨_, F.preimage ((F.objObjPreimageIso Y).hom ≫ f), (F.objObjPreimageIso Y).inv, ?_⟩ simpa using hf /-- When `F` is fully faithful, the Galois connection is a Galois coinsertion. -/ def fullyFaithfulFunctorGaloisCoinsertion [F.Full] [F.Faithful] (X : C) : GaloisCoinsertion (Sieve.functorPushforward F : Sieve X → Sieve (F.obj X)) (Sieve.functorPullback F) := by apply (functor_galoisConnection F X).toGaloisCoinsertion rintro S Y f ⟨Z, g, h, h₁, h₂⟩ rw [← F.map_preimage h, ← F.map_comp] at h₂ rw [F.map_injective h₂] exact S.downward_closed h₁ _ lemma functorPushforward_functor (S : Sieve X) (e : C ≌ D) : S.functorPushforward e.functor = (S.pullback (e.unitInv.app X)).functorPullback e.inverse := by ext Y iYX constructor · rintro ⟨Z, iZX, iYZ, hiZX, rfl⟩ simpa using S.downward_closed hiZX (e.inverse.map iYZ ≫ e.unitInv.app Z) · intro H exact ⟨_, e.inverse.map iYX ≫ e.unitInv.app X, e.counitInv.app Y, by simpa using H, by simp⟩ @[simp] lemma mem_functorPushforward_functor {Y : D} {S : Sieve X} {e : C ≌ D} {f : Y ⟶ e.functor.obj X} : S.functorPushforward e.functor f ↔ S (e.inverse.map f ≫ e.unitInv.app X) := congr($(S.functorPushforward_functor e).arrows f) lemma functorPushforward_inverse {X : D} (S : Sieve X) (e : C ≌ D) : S.functorPushforward e.inverse = (S.pullback (e.counit.app X)).functorPullback e.functor := Sieve.functorPushforward_functor S e.symm @[simp] lemma mem_functorPushforward_inverse {X : D} {S : Sieve X} {e : C ≌ D} {f : Y ⟶ e.inverse.obj X} : S.functorPushforward e.inverse f ↔ S (e.functor.map f ≫ e.counit.app X) := congr($(S.functorPushforward_inverse e).arrows f) variable (e : C ≌ D) lemma functorPushforward_equivalence_eq_pullback {U : C} (S : Sieve U) : Sieve.functorPushforward e.inverse (Sieve.functorPushforward e.functor S) = Sieve.pullback (e.unitInv.app U) S := by ext; simp lemma pullback_functorPushforward_equivalence_eq {X : C} (S : Sieve X) : Sieve.pullback (e.unit.app X) (Sieve.functorPushforward e.inverse (Sieve.functorPushforward e.functor S)) = S := by ext; simp lemma mem_functorPushforward_iff_of_full [F.Full] {X Y : C} (R : Sieve X) (f : F.obj Y ⟶ F.obj X) : (R.arrows.functorPushforward F) f ↔ ∃ (g : Y ⟶ X), F.map g = f ∧ R g := by refine ⟨fun ⟨Z, g, h, hg, hcomp⟩ ↦ ?_, fun ⟨g, hcomp, hg⟩ ↦ ?_⟩ · obtain ⟨h', hh'⟩ := F.map_surjective h use h' ≫ g simp only [Functor.map_comp, hh', hcomp, true_and] apply R.downward_closed hg · use Y, g, 𝟙 _, hg simp [hcomp] lemma mem_functorPushforward_iff_of_full_of_faithful [F.Full] [F.Faithful] {X Y : C} (R : Sieve X) (f : Y ⟶ X) : (R.arrows.functorPushforward F) (F.map f) ↔ R f := by rw [Sieve.mem_functorPushforward_iff_of_full] refine ⟨fun ⟨g, hcomp, hg⟩ ↦ ?_, fun hf ↦ ⟨f, rfl, hf⟩⟩ rwa [← F.map_injective hcomp] end Functor /-- A sieve induces a presheaf. -/ @[simps] def functor (S : Sieve X) : Cᵒᵖ ⥤ Type v₁ where obj Y := { g : Y.unop ⟶ X // S g } map f g := ⟨f.unop ≫ g.1, downward_closed _ g.2 _⟩ /-- If a sieve S is contained in a sieve T, then we have a morphism of presheaves on their induced presheaves. -/ @[simps] def natTransOfLe {S T : Sieve X} (h : S ≤ T) : S.functor ⟶ T.functor where app _ f := ⟨f.1, h _ f.2⟩ /-- The natural inclusion from the functor induced by a sieve to the yoneda embedding. -/ @[simps] def functorInclusion (S : Sieve X) : S.functor ⟶ yoneda.obj X where app _ f := f.1 theorem natTransOfLe_comm {S T : Sieve X} (h : S ≤ T) : natTransOfLe h ≫ functorInclusion _ = functorInclusion _ := rfl /-- The presheaf induced by a sieve is a subobject of the yoneda embedding. -/ instance functorInclusion_is_mono : Mono S.functorInclusion := ⟨fun f g h => by ext Y y simpa [Subtype.ext_iff] using congr_fun (NatTrans.congr_app h Y) y⟩ -- TODO: Show that when `f` is mono, this is right inverse to `functorInclusion` up to isomorphism. /-- A natural transformation to a representable functor induces a sieve. This is the left inverse of `functorInclusion`, shown in `sieveOfSubfunctor_functorInclusion`. -/ @[simps] def sieveOfSubfunctor {R} (f : R ⟶ yoneda.obj X) : Sieve X where arrows Y g := ∃ t, f.app (Opposite.op Y) t = g downward_closed := by rintro Y Z _ ⟨t, rfl⟩ g refine ⟨R.map g.op t, ?_⟩ rw [FunctorToTypes.naturality _ _ f] simp theorem sieveOfSubfunctor_functorInclusion : sieveOfSubfunctor S.functorInclusion = S := by ext simp only [functorInclusion_app, sieveOfSubfunctor_apply] constructor · rintro ⟨⟨f, hf⟩, rfl⟩ exact hf · intro hf exact ⟨⟨_, hf⟩, rfl⟩ instance functorInclusion_top_isIso : IsIso (⊤ : Sieve X).functorInclusion := ⟨⟨{ app := fun _ a => ⟨a, ⟨⟩⟩ }, rfl, rfl⟩⟩ lemma ofArrows_eq_pullback_of_isPullback {ι : Type*} {S : C} {X : ι → C} (f : (i : ι) → X i ⟶ S) {Y : C} {g : Y ⟶ S} {P : ι → C} {p₁ : (i : ι) → P i ⟶ Y} {p₂ : (i : ι) → P i ⟶ X i} (h : ∀ (i : ι), IsPullback (p₁ i) (p₂ i) g (f i)) : Sieve.ofArrows P p₁ = Sieve.pullback g (Sieve.ofArrows X f) := by refine le_antisymm ?_ ?_ · rw [Sieve.ofArrows, Sieve.generate_le_iff] rintro - - ⟨i⟩ use X i, p₂ i, f i, ⟨i⟩ exact (h i).w.symm · rintro W u ⟨Z, v, s, ⟨i⟩, heq⟩ use P i, (h i).lift u v heq.symm, p₁ i, ⟨i⟩ simp end Sieve lemma Presieve.bind_ofArrows_le_bindOfArrows {ι : Type*} {X : C} (Z : ι → C) (f : ∀ i, Z i ⟶ X) (R : ∀ i, Presieve (Z i)) : Sieve.bind (Sieve.ofArrows Z f) (fun _ _ hg ↦ Sieve.pullback (Sieve.ofArrows.h hg) (.generate <| R (Sieve.ofArrows.i hg))) ≤ Sieve.generate (Presieve.bindOfArrows Z f R) := by rintro T g ⟨W, v, v', hv', ⟨S, u, u', h, hu⟩, rfl⟩ rw [← Sieve.ofArrows.fac hv', ← reassoc_of% hu] exact ⟨S, u, u' ≫ f _, ⟨_, _, h⟩, rfl⟩ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Plus.lean
import Mathlib.CategoryTheory.Sites.Sheaf /-! # The plus construction for presheaves. This file contains the construction of `P⁺`, for a presheaf `P : Cᵒᵖ ⥤ D` where `C` is endowed with a Grothendieck topology `J`. See <https://stacks.math.columbia.edu/tag/00W1> for details. -/ namespace CategoryTheory.GrothendieckTopology open CategoryTheory open CategoryTheory.Limits open Opposite universe w' w v u variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) variable {D : Type w} [Category.{w'} D] noncomputable section variable [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.Cover X), HasMultiequalizer (S.index P)] variable (P : Cᵒᵖ ⥤ D) /-- The diagram whose colimit defines the values of `plus`. -/ @[simps] def diagram (X : C) : (J.Cover X)ᵒᵖ ⥤ D where obj S := multiequalizer (S.unop.index P) map {S _} f := Multiequalizer.lift _ _ (fun I => Multiequalizer.ι (S.unop.index P) (I.map f.unop)) (fun I => Multiequalizer.condition (S.unop.index P) (Cover.Relation.mk' (I.r.map f.unop))) /-- A helper definition used to define the morphisms for `plus`. -/ @[simps] def diagramPullback {X Y : C} (f : X ⟶ Y) : J.diagram P Y ⟶ (J.pullback f).op ⋙ J.diagram P X where app S := Multiequalizer.lift _ _ (fun I => Multiequalizer.ι (S.unop.index P) I.base) fun I => Multiequalizer.condition (S.unop.index P) (Cover.Relation.mk' I.r.base) naturality S T f := Multiequalizer.hom_ext _ _ _ (fun I => by simp; rfl) /-- A natural transformation `P ⟶ Q` induces a natural transformation between diagrams whose colimits define the values of `plus`. -/ @[simps] def diagramNatTrans {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (X : C) : J.diagram P X ⟶ J.diagram Q X where app W := Multiequalizer.lift _ _ (fun _ => Multiequalizer.ι _ _ ≫ η.app _) (fun i => by dsimp only erw [Category.assoc, Category.assoc, ← η.naturality, ← η.naturality, Multiequalizer.condition_assoc] rfl) @[simp] theorem diagramNatTrans_id (X : C) (P : Cᵒᵖ ⥤ D) : J.diagramNatTrans (𝟙 P) X = 𝟙 (J.diagram P X) := by ext : 2 refine Multiequalizer.hom_ext _ _ _ (fun i => ?_) simp @[simp] theorem diagramNatTrans_zero [Preadditive D] (X : C) (P Q : Cᵒᵖ ⥤ D) : J.diagramNatTrans (0 : P ⟶ Q) X = 0 := by ext : 2 refine Multiequalizer.hom_ext _ _ _ (fun i => ?_) simp @[simp] theorem diagramNatTrans_comp {P Q R : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (γ : Q ⟶ R) (X : C) : J.diagramNatTrans (η ≫ γ) X = J.diagramNatTrans η X ≫ J.diagramNatTrans γ X := by ext : 2 refine Multiequalizer.hom_ext _ _ _ (fun i => ?_) simp variable (D) in /-- `J.diagram P`, as a functor in `P`. -/ @[simps] def diagramFunctor (X : C) : (Cᵒᵖ ⥤ D) ⥤ (J.Cover X)ᵒᵖ ⥤ D where obj P := J.diagram P X map η := J.diagramNatTrans η X variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] /-- The plus construction, associating a presheaf to any presheaf. See `plusFunctor` below for a functorial version. -/ def plusObj : Cᵒᵖ ⥤ D where obj X := colimit (J.diagram P X.unop) map f := colimMap (J.diagramPullback P f.unop) ≫ colimit.pre _ _ map_id := by intro X refine colimit.hom_ext (fun S => ?_) dsimp simp only [diagramPullback_app, colimit.ι_pre, ι_colimMap_assoc, Category.comp_id] let e := S.unop.pullbackId dsimp only [Functor.op, pullback_obj] rw [← colimit.w _ e.inv.op, ← Category.assoc] convert Category.id_comp (colimit.ι (diagram J P (unop X)) S) refine Multiequalizer.hom_ext _ _ _ (fun I => ?_) dsimp simp only [Multiequalizer.lift_ι, Category.id_comp, Category.assoc] dsimp [Cover.Arrow.map, Cover.Arrow.base] cases I congr simp map_comp := by intro X Y Z f g refine colimit.hom_ext (fun S => ?_) dsimp simp only [diagramPullback_app, colimit.ι_pre_assoc, colimit.ι_pre, ι_colimMap_assoc, Category.assoc] let e := S.unop.pullbackComp g.unop f.unop dsimp only [Functor.op, pullback_obj] rw [← colimit.w _ e.inv.op, ← Category.assoc, ← Category.assoc] congr 1 refine Multiequalizer.hom_ext _ _ _ (fun I => ?_) dsimp simp only [Multiequalizer.lift_ι, Category.assoc] cases I dsimp only [Cover.Arrow.base, Cover.Arrow.map] congr 2 simp /-- An auxiliary definition used in `plus` below. -/ def plusMap {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : J.plusObj P ⟶ J.plusObj Q where app X := colimMap (J.diagramNatTrans η X.unop) naturality := by intro X Y f dsimp [plusObj] ext simp only [diagramPullback_app, ι_colimMap, colimit.ι_pre_assoc, colimit.ι_pre, ι_colimMap_assoc, Category.assoc] simp_rw [← Category.assoc] congr 1 exact Multiequalizer.hom_ext _ _ _ (fun I => by simp) @[simp] theorem plusMap_id (P : Cᵒᵖ ⥤ D) : J.plusMap (𝟙 P) = 𝟙 _ := by ext : 2 dsimp only [plusMap, plusObj] rw [J.diagramNatTrans_id, NatTrans.id_app] ext simp @[simp] theorem plusMap_zero [Preadditive D] (P Q : Cᵒᵖ ⥤ D) : J.plusMap (0 : P ⟶ Q) = 0 := by ext : 2 refine colimit.hom_ext (fun S => ?_) erw [comp_zero, colimit.ι_map, J.diagramNatTrans_zero, zero_comp] @[simp, reassoc] theorem plusMap_comp {P Q R : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (γ : Q ⟶ R) : J.plusMap (η ≫ γ) = J.plusMap η ≫ J.plusMap γ := by ext : 2 refine colimit.hom_ext (fun S => ?_) simp [plusMap, J.diagramNatTrans_comp] variable (D) in /-- The plus construction, a functor sending `P` to `J.plusObj P`. -/ @[simps] def plusFunctor : (Cᵒᵖ ⥤ D) ⥤ Cᵒᵖ ⥤ D where obj P := J.plusObj P map η := J.plusMap η /-- The canonical map from `P` to `J.plusObj P`. See `toPlusNatTrans` for a functorial version. -/ def toPlus : P ⟶ J.plusObj P where app X := Cover.toMultiequalizer (⊤ : J.Cover X.unop) P ≫ colimit.ι (J.diagram P X.unop) (op ⊤) naturality := by intro X Y f dsimp [plusObj] delta Cover.toMultiequalizer simp only [diagramPullback_app, colimit.ι_pre, ι_colimMap_assoc, Category.assoc] dsimp only [Functor.op, unop_op] let e : (J.pullback f.unop).obj ⊤ ⟶ ⊤ := homOfLE (OrderTop.le_top _) rw [← colimit.w _ e.op, ← Category.assoc, ← Category.assoc, ← Category.assoc] congr 1 refine Multiequalizer.hom_ext _ _ _ (fun I => ?_) simp only [Category.assoc] dsimp [Cover.Arrow.base] simp @[reassoc (attr := simp)] theorem toPlus_naturality {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : η ≫ J.toPlus Q = J.toPlus _ ≫ J.plusMap η := by ext dsimp [toPlus, plusMap] delta Cover.toMultiequalizer simp only [ι_colimMap, Category.assoc] simp_rw [← Category.assoc] congr 1 exact Multiequalizer.hom_ext _ _ _ (fun I => by simp) variable (D) in /-- The natural transformation from the identity functor to `plus`. -/ @[simps] def toPlusNatTrans : 𝟭 (Cᵒᵖ ⥤ D) ⟶ J.plusFunctor D where app P := J.toPlus P /-- `(P ⟶ P⁺)⁺ = P⁺ ⟶ P⁺⁺` -/ @[simp] theorem plusMap_toPlus : J.plusMap (J.toPlus P) = J.toPlus (J.plusObj P) := by ext X : 2 refine colimit.hom_ext (fun S => ?_) dsimp only [plusMap, toPlus] let e : S.unop ⟶ ⊤ := homOfLE (OrderTop.le_top _) rw [ι_colimMap, ← colimit.w _ e.op, ← Category.assoc, ← Category.assoc] congr 1 refine Multiequalizer.hom_ext _ _ _ (fun I => ?_) erw [Multiequalizer.lift_ι] simp only [unop_op, op_unop, diagram_map, Category.assoc, limit.lift_π, Multifork.ofι_π_app] let ee : (J.pullback (I.map e).f).obj S.unop ⟶ ⊤ := homOfLE (OrderTop.le_top _) erw [← colimit.w _ ee.op, ι_colimMap_assoc, colimit.ι_pre, diagramPullback_app, ← Category.assoc, ← Category.assoc] congr 1 refine Multiequalizer.hom_ext _ _ _ (fun II => ?_) convert Multiequalizer.condition (S.unop.index P) { fst := I, snd := II.base, r.Z := II.Y, r.g₁ := II.f, r.g₂ := 𝟙 II.Y } using 1 all_goals simp theorem isIso_toPlus_of_isSheaf (hP : Presheaf.IsSheaf J P) : IsIso (J.toPlus P) := by rw [Presheaf.isSheaf_iff_multiequalizer] at hP suffices ∀ X, IsIso ((J.toPlus P).app X) from NatIso.isIso_of_isIso_app _ intro X refine IsIso.comp_isIso' inferInstance ?_ suffices ∀ (S T : (J.Cover X.unop)ᵒᵖ) (f : S ⟶ T), IsIso ((J.diagram P X.unop).map f) from isIso_ι_of_isInitial (initialOpOfTerminal isTerminalTop) _ intro S T e have : S.unop.toMultiequalizer P ≫ (J.diagram P X.unop).map e = T.unop.toMultiequalizer P := Multiequalizer.hom_ext _ _ _ (fun II => by simp) have : (J.diagram P X.unop).map e = inv (S.unop.toMultiequalizer P) ≫ T.unop.toMultiequalizer P := by simp [← this] rw [this] infer_instance /-- The natural isomorphism between `P` and `P⁺` when `P` is a sheaf. -/ def isoToPlus (hP : Presheaf.IsSheaf J P) : P ≅ J.plusObj P := letI := isIso_toPlus_of_isSheaf J P hP asIso (J.toPlus P) @[simp] theorem isoToPlus_hom (hP : Presheaf.IsSheaf J P) : (J.isoToPlus P hP).hom = J.toPlus P := rfl /-- Lift a morphism `P ⟶ Q` to `P⁺ ⟶ Q` when `Q` is a sheaf. -/ def plusLift {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (hQ : Presheaf.IsSheaf J Q) : J.plusObj P ⟶ Q := J.plusMap η ≫ (J.isoToPlus Q hQ).inv @[reassoc (attr := simp)] theorem toPlus_plusLift {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (hQ : Presheaf.IsSheaf J Q) : J.toPlus P ≫ J.plusLift η hQ = η := by dsimp [plusLift] rw [← Category.assoc] rw [Iso.comp_inv_eq] dsimp only [isoToPlus, asIso] rw [toPlus_naturality] theorem plusLift_unique {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (hQ : Presheaf.IsSheaf J Q) (γ : J.plusObj P ⟶ Q) (hγ : J.toPlus P ≫ γ = η) : γ = J.plusLift η hQ := by dsimp only [plusLift] rw [Iso.eq_comp_inv, ← hγ, plusMap_comp] simp theorem plus_hom_ext {P Q : Cᵒᵖ ⥤ D} (η γ : J.plusObj P ⟶ Q) (hQ : Presheaf.IsSheaf J Q) (h : J.toPlus P ≫ η = J.toPlus P ≫ γ) : η = γ := by have : γ = J.plusLift (J.toPlus P ≫ γ) hQ := by apply plusLift_unique rfl rw [this] apply plusLift_unique exact h @[simp] theorem isoToPlus_inv (hP : Presheaf.IsSheaf J P) : (J.isoToPlus P hP).inv = J.plusLift (𝟙 _) hP := by apply J.plusLift_unique rw [Iso.comp_inv_eq, Category.id_comp] rfl @[simp] theorem plusMap_plusLift {P Q R : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (γ : Q ⟶ R) (hR : Presheaf.IsSheaf J R) : J.plusMap η ≫ J.plusLift γ hR = J.plusLift (η ≫ γ) hR := by apply J.plusLift_unique rw [← Category.assoc, ← J.toPlus_naturality, Category.assoc, J.toPlus_plusLift] instance plusFunctor_preservesZeroMorphisms [Preadditive D] : (plusFunctor J D).PreservesZeroMorphisms where map_zero F G := by ext dsimp rw [J.plusMap_zero, NatTrans.app_zero] end end CategoryTheory.GrothendieckTopology
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/LocallyInjective.lean
import Mathlib.CategoryTheory.Sites.LeftExact import Mathlib.CategoryTheory.Sites.PreservesSheafification import Mathlib.CategoryTheory.Sites.Subsheaf import Mathlib.CategoryTheory.Sites.Whiskering /-! # Locally injective morphisms of (pre)sheaves Let `C` be a category equipped with a Grothendieck topology `J`, and let `D` be a concrete category. In this file, we introduce the typeclass `Presheaf.IsLocallyInjective J φ` for a morphism `φ : F₁ ⟶ F₂` in the category `Cᵒᵖ ⥤ D`. This means that `φ` is locally injective. More precisely, if `x` and `y` are two elements of some `F₁.obj U` such the images of `x` and `y` in `F₂.obj U` coincide, then the equality `x = y` must hold locally, i.e. after restriction by the maps of a covering sieve. -/ universe w v' v u' u namespace CategoryTheory open Opposite Limits variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] {FD : D → D → Type*} {CD : D → Type w} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{w} D FD] (J : GrothendieckTopology C) namespace Presheaf /-- If `F : Cᵒᵖ ⥤ D` is a presheaf with values in a concrete category, if `x` and `y` are elements in `F.obj X`, this is the sieve of `X.unop` consisting of morphisms `f` such that `F.map f.op x = F.map f.op y`. -/ @[simps] def equalizerSieve {F : Cᵒᵖ ⥤ D} {X : Cᵒᵖ} (x y : ToType (F.obj X)) : Sieve X.unop where arrows _ f := F.map f.op x = F.map f.op y downward_closed {X Y} f hf g := by dsimp at hf ⊢ simp [hf] @[simp] lemma equalizerSieve_self_eq_top {F : Cᵒᵖ ⥤ D} {X : Cᵒᵖ} (x : ToType (F.obj X)) : equalizerSieve x x = ⊤ := by aesop @[simp] lemma equalizerSieve_eq_top_iff {F : Cᵒᵖ ⥤ D} {X : Cᵒᵖ} (x y : ToType (F.obj X)) : equalizerSieve x y = ⊤ ↔ x = y := by constructor · intro h simpa using (show equalizerSieve x y (𝟙 _) by simp [h]) · rintro rfl apply equalizerSieve_self_eq_top variable {F₁ F₂ F₃ : Cᵒᵖ ⥤ D} (φ : F₁ ⟶ F₂) (ψ : F₂ ⟶ F₃) /-- A morphism `φ : F₁ ⟶ F₂` of presheaves `Cᵒᵖ ⥤ D` (with `D` a concrete category) is locally injective for a Grothendieck topology `J` on `C` if whenever two sections of `F₁` are sent to the same section of `F₂`, then these two sections coincide locally. -/ class IsLocallyInjective : Prop where equalizerSieve_mem {X : Cᵒᵖ} (x y : ToType (F₁.obj X)) (h : φ.app X x = φ.app X y) : equalizerSieve x y ∈ J X.unop lemma equalizerSieve_mem [IsLocallyInjective J φ] {X : Cᵒᵖ} (x y : ToType (F₁.obj X)) (h : φ.app X x = φ.app X y) : equalizerSieve x y ∈ J X.unop := IsLocallyInjective.equalizerSieve_mem x y h lemma isLocallyInjective_of_injective (hφ : ∀ (X : Cᵒᵖ), Function.Injective (φ.app X)) : IsLocallyInjective J φ where equalizerSieve_mem {X} x y h := by convert J.top_mem X.unop ext Y f simp only [equalizerSieve_apply, op_unop, Sieve.top_apply, iff_true] apply hφ simp [h] instance [IsIso φ] : IsLocallyInjective J φ := isLocallyInjective_of_injective J φ (fun X => Function.Bijective.injective (by rw [← isIso_iff_bijective] change IsIso ((forget D).map (φ.app X)) infer_instance)) attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance isLocallyInjective_forget [IsLocallyInjective J φ] : IsLocallyInjective J (Functor.whiskerRight φ (forget D)) where equalizerSieve_mem x y h := equalizerSieve_mem J φ x y h attribute [local instance] Types.instFunLike Types.instConcreteCategory in lemma isLocallyInjective_forget_iff : IsLocallyInjective J (Functor.whiskerRight φ (forget D)) ↔ IsLocallyInjective J φ := by constructor · intro exact ⟨fun x y h => equalizerSieve_mem J (Functor.whiskerRight φ (forget D)) x y h⟩ · intro infer_instance lemma isLocallyInjective_iff_equalizerSieve_mem_imp : IsLocallyInjective J φ ↔ ∀ ⦃X : Cᵒᵖ⦄ (x y : ToType (F₁.obj X)), equalizerSieve (φ.app _ x) (φ.app _ y) ∈ J X.unop → equalizerSieve x y ∈ J X.unop := by constructor · intro _ X x y h let S := equalizerSieve (φ.app _ x) (φ.app _ y) let T : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X.unop⦄ (_ : S f), Sieve Y := fun Y f _ => equalizerSieve (F₁.map f.op x) ((F₁.map f.op y)) refine J.superset_covering ?_ (J.transitive h (Sieve.bind S.1 T) ?_) · rintro Y f ⟨Z, a, g, hg, ha, rfl⟩ simpa using ha · intro Y f hf refine J.superset_covering (Sieve.le_pullback_bind S.1 T _ hf) (equalizerSieve_mem J φ _ _ ?_) rw [NatTrans.naturality_apply, NatTrans.naturality_apply] exact hf · intro hφ exact ⟨fun {X} x y h => hφ x y (by simp [h])⟩ lemma equalizerSieve_mem_of_equalizerSieve_app_mem {X : Cᵒᵖ} (x y : ToType (F₁.obj X)) (h : equalizerSieve (φ.app _ x) (φ.app _ y) ∈ J X.unop) [IsLocallyInjective J φ] : equalizerSieve x y ∈ J X.unop := (isLocallyInjective_iff_equalizerSieve_mem_imp J φ).1 inferInstance x y h instance isLocallyInjective_comp [IsLocallyInjective J φ] [IsLocallyInjective J ψ] : IsLocallyInjective J (φ ≫ ψ) where equalizerSieve_mem {X} x y h := by apply equalizerSieve_mem_of_equalizerSieve_app_mem J φ exact equalizerSieve_mem J ψ _ _ (by simpa using h) lemma isLocallyInjective_of_isLocallyInjective [IsLocallyInjective J (φ ≫ ψ)] : IsLocallyInjective J φ where equalizerSieve_mem {X} x y h := equalizerSieve_mem J (φ ≫ ψ) x y (by simp [h]) variable {φ ψ} lemma isLocallyInjective_of_isLocallyInjective_fac {φψ : F₁ ⟶ F₃} (fac : φ ≫ ψ = φψ) [IsLocallyInjective J φψ] : IsLocallyInjective J φ := by subst fac exact isLocallyInjective_of_isLocallyInjective J φ ψ lemma isLocallyInjective_iff_of_fac {φψ : F₁ ⟶ F₃} (fac : φ ≫ ψ = φψ) [IsLocallyInjective J ψ] : IsLocallyInjective J φψ ↔ IsLocallyInjective J φ := by constructor · intro exact isLocallyInjective_of_isLocallyInjective_fac J fac · intro rw [← fac] infer_instance variable (φ ψ) lemma isLocallyInjective_comp_iff [IsLocallyInjective J ψ] : IsLocallyInjective J (φ ≫ ψ) ↔ IsLocallyInjective J φ := isLocallyInjective_iff_of_fac J rfl lemma isLocallyInjective_iff_injective_of_separated (hsep : Presieve.IsSeparated J (F₁ ⋙ forget D)) : IsLocallyInjective J φ ↔ ∀ (X : Cᵒᵖ), Function.Injective (φ.app X) := by constructor · intro _ X x y h exact (hsep _ (equalizerSieve_mem J φ x y h)).ext (fun _ _ hf => hf) · apply isLocallyInjective_of_injective attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance (F : Cᵒᵖ ⥤ Type w) (G : Subpresheaf F) : IsLocallyInjective J G.ι := isLocallyInjective_of_injective _ _ (fun X => by intro ⟨x, _⟩ ⟨y, _⟩ h exact Subtype.ext h) section open GrothendieckTopology.Plus attribute [local instance] Types.instFunLike Types.instConcreteCategory instance isLocallyInjective_toPlus (P : Cᵒᵖ ⥤ Type max u v) : IsLocallyInjective J (J.toPlus P) where equalizerSieve_mem {X} x y h := by rw [toPlus_eq_mk, toPlus_eq_mk, eq_mk_iff_exists] at h obtain ⟨W, h₁, h₂, eq⟩ := h exact J.superset_covering (fun Y f hf => congr_fun (congr_arg Subtype.val eq) ⟨Y, f, hf⟩) W.2 instance isLocallyInjective_toSheafify (P : Cᵒᵖ ⥤ Type max u v) : IsLocallyInjective J (J.toSheafify P) := by dsimp [GrothendieckTopology.toSheafify] rw [GrothendieckTopology.plusMap_toPlus] infer_instance instance isLocallyInjective_toSheafify' {CD : D → Type (max u v)} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{max u v} D FD] (P : Cᵒᵖ ⥤ D) [HasWeakSheafify J D] [J.HasSheafCompose (forget D)] [J.PreservesSheafification (forget D)] : IsLocallyInjective J (toSheafify J P) := by rw [← isLocallyInjective_forget_iff, ← sheafComposeIso_hom_fac, ← toSheafify_plusPlusIsoSheafify_hom] infer_instance end end Presheaf namespace Sheaf variable {J} variable {F₁ F₂ : Sheaf J D} (φ : F₁ ⟶ F₂) /-- If `φ : F₁ ⟶ F₂` is a morphism of sheaves, this is an abbreviation for `Presheaf.IsLocallyInjective J φ.val`. Under suitable assumptions, it is equivalent to the injectivity of all maps `φ.val.app X`, see `isLocallyInjective_iff_injective`. -/ abbrev IsLocallyInjective := Presheaf.IsLocallyInjective J φ.val lemma isLocallyInjective_sheafToPresheaf_map_iff : Presheaf.IsLocallyInjective J ((sheafToPresheaf J D).map φ) ↔ IsLocallyInjective φ := by rfl instance isLocallyInjective_of_iso [IsIso φ] : IsLocallyInjective φ := by change Presheaf.IsLocallyInjective J ((sheafToPresheaf _ _).map φ) infer_instance lemma mono_of_injective (hφ : ∀ (X : Cᵒᵖ), Function.Injective (φ.val.app X)) : Mono φ := have : ∀ X, Mono (φ.val.app X) := fun X ↦ ConcreteCategory.mono_of_injective _ (hφ X) (sheafToPresheaf _ _).mono_of_mono_map (NatTrans.mono_of_mono_app φ.1) variable [J.HasSheafCompose (forget D)] attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance isLocallyInjective_forget [IsLocallyInjective φ] : IsLocallyInjective ((sheafCompose J (forget D)).map φ) := Presheaf.isLocallyInjective_forget J φ.1 lemma isLocallyInjective_iff_injective : IsLocallyInjective φ ↔ ∀ (X : Cᵒᵖ), Function.Injective (φ.val.app X) := Presheaf.isLocallyInjective_iff_injective_of_separated _ _ (by apply Presieve.IsSheaf.isSeparated rw [← isSheaf_iff_isSheaf_of_type] exact ((sheafCompose J (forget D)).obj F₁).2) lemma mono_of_isLocallyInjective [IsLocallyInjective φ] : Mono φ := by apply mono_of_injective rw [← isLocallyInjective_iff_injective] infer_instance attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance {F G : Sheaf J (Type w)} (f : F ⟶ G) : IsLocallyInjective (Sheaf.imageι f) := by dsimp [Sheaf.imageι] infer_instance end Sheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/CompatiblePlus.lean
import Mathlib.CategoryTheory.Sites.Whiskering import Mathlib.CategoryTheory.Sites.Plus /-! In this file, we prove that the plus functor is compatible with functors which preserve the correct limits and colimits. See `CategoryTheory/Sites/CompatibleSheafification` for the compatibility of sheafification, which follows easily from the content in this file. -/ noncomputable section namespace CategoryTheory.GrothendieckTopology open CategoryTheory Limits Opposite Functor universe w₁ w₂ v u variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) variable {D : Type w₁} [Category.{max v u} D] variable {E : Type w₂} [Category.{max v u} E] variable (F : D ⥤ E) variable [∀ (J : MulticospanShape.{max v u, max v u}), HasLimitsOfShape (WalkingMulticospan J) D] variable [∀ (J : MulticospanShape.{max v u, max v u}), HasLimitsOfShape (WalkingMulticospan J) E] variable [∀ (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F] variable (P : Cᵒᵖ ⥤ D) /-- The diagram used to define `P⁺`, composed with `F`, is isomorphic to the diagram used to define `P ⋙ F`. -/ def diagramCompIso (X : C) : J.diagram P X ⋙ F ≅ J.diagram (P ⋙ F) X := NatIso.ofComponents (fun W => by refine ?_ ≪≫ HasLimit.isoOfNatIso (W.unop.multicospanComp _ _).symm refine (isLimitOfPreserves F (limit.isLimit _)).conePointUniqueUpToIso (limit.isLimit _)) (by intro A B f dsimp ext g simp [← F.map_comp]) @[reassoc (attr := simp)] theorem diagramCompIso_hom_ι (X : C) (W : (J.Cover X)ᵒᵖ) (i : W.unop.Arrow) : (J.diagramCompIso F P X).hom.app W ≫ Multiequalizer.ι ((unop W).index (P ⋙ F)) i = F.map (Multiequalizer.ι _ _) := by delta diagramCompIso simp variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ E] variable [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ F] /-- The isomorphism between `P⁺ ⋙ F` and `(P ⋙ F)⁺`. -/ def plusCompIso : J.plusObj P ⋙ F ≅ J.plusObj (P ⋙ F) := NatIso.ofComponents (fun X => by refine ?_ ≪≫ HasColimit.isoOfNatIso (J.diagramCompIso F P X.unop) refine (isColimitOfPreserves F (colimit.isColimit (J.diagram P (unop X)))).coconePointUniqueUpToIso (colimit.isColimit _)) (by intro X Y f apply (isColimitOfPreserves F (colimit.isColimit (J.diagram P X.unop))).hom_ext intro W dsimp [plusObj, plusMap] simp only [Functor.map_comp, Category.assoc] slice_rhs 1 2 => erw [(isColimitOfPreserves F (colimit.isColimit (J.diagram P X.unop))).fac] slice_lhs 1 3 => simp only [← F.map_comp] dsimp [colimMap, IsColimit.map, colimit.pre] simp only [colimit.ι_desc_assoc, colimit.ι_desc] dsimp [Cocones.precompose] simp only [Category.assoc, colimit.ι_desc] dsimp [Cocone.whisker] rw [F.map_comp] simp only [Category.assoc] slice_lhs 2 3 => erw [(isColimitOfPreserves F (colimit.isColimit (J.diagram P Y.unop))).fac] dsimp simp only [HasColimit.isoOfNatIso_ι_hom_assoc, GrothendieckTopology.diagramPullback_app, colimit.ι_pre, HasColimit.isoOfNatIso_ι_hom, ι_colimMap_assoc] simp only [← Category.assoc] dsimp congr 1 ext dsimp simp only [Category.assoc] rw [Multiequalizer.lift_ι, diagramCompIso_hom_ι, diagramCompIso_hom_ι, ← F.map_comp, Multiequalizer.lift_ι]) @[reassoc (attr := simp)] theorem ι_plusCompIso_hom (X) (W) : F.map (colimit.ι _ W) ≫ (J.plusCompIso F P).hom.app X = (J.diagramCompIso F P X.unop).hom.app W ≫ colimit.ι _ W := by delta diagramCompIso plusCompIso simp only [Iso.trans_hom, NatIso.ofComponents_hom_app, ← Category.assoc] erw [(isColimitOfPreserves F (colimit.isColimit (J.diagram P (unop X)))).fac] simp @[reassoc (attr := simp)] theorem plusCompIso_whiskerLeft {F G : D ⥤ E} (η : F ⟶ G) (P : Cᵒᵖ ⥤ D) [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ F] [∀ (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F] [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ G] [∀ (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan G] : whiskerLeft _ η ≫ (J.plusCompIso G P).hom = (J.plusCompIso F P).hom ≫ J.plusMap (whiskerLeft _ η) := by ext X apply (isColimitOfPreserves F (colimit.isColimit (J.diagram P X.unop))).hom_ext intro W dsimp [plusObj, plusMap] simp only [ι_plusCompIso_hom, ι_colimMap, whiskerLeft_app, ι_plusCompIso_hom_assoc, NatTrans.naturality_assoc, GrothendieckTopology.diagramNatTrans_app] simp only [← Category.assoc] congr 1 cat_disch /-- The isomorphism between `P⁺ ⋙ F` and `(P ⋙ F)⁺`, functorially in `F`. -/ @[simps! hom_app inv_app] def plusFunctorWhiskerLeftIso (P : Cᵒᵖ ⥤ D) [∀ (F : D ⥤ E) (X : C), PreservesColimitsOfShape (J.Cover X)ᵒᵖ F] [∀ (F : D ⥤ E) (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F] : (whiskeringLeft _ _ E).obj (J.plusObj P) ≅ (whiskeringLeft _ _ _).obj P ⋙ J.plusFunctor E := NatIso.ofComponents (fun _ => plusCompIso _ _ _) @fun _ _ _ => plusCompIso_whiskerLeft _ _ _ @[reassoc (attr := simp)] theorem plusCompIso_whiskerRight {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : whiskerRight (J.plusMap η) F ≫ (J.plusCompIso F Q).hom = (J.plusCompIso F P).hom ≫ J.plusMap (whiskerRight η F) := by ext X apply (isColimitOfPreserves F (colimit.isColimit (J.diagram P X.unop))).hom_ext intro W dsimp [plusObj, plusMap] simp only [ι_colimMap, whiskerRight_app, ι_plusCompIso_hom_assoc, GrothendieckTopology.diagramNatTrans_app] simp only [← Category.assoc, ← F.map_comp] dsimp [colimMap, IsColimit.map] simp only [colimit.ι_desc] dsimp [Cocones.precompose] simp only [Functor.map_comp, Category.assoc, ι_plusCompIso_hom] simp only [← Category.assoc] congr 1 dsimp only [diagram] -- Need to unfold `diagram` before `ext` applies. ext a dsimp simp only [diagramCompIso_hom_ι_assoc, Multiequalizer.lift_ι, diagramCompIso_hom_ι, Category.assoc] simp only [← F.map_comp, Multiequalizer.lift_ι] /-- The isomorphism between `P⁺ ⋙ F` and `(P ⋙ F)⁺`, functorially in `P`. -/ @[simps! hom_app inv_app] def plusFunctorWhiskerRightIso : J.plusFunctor D ⋙ (whiskeringRight _ _ _).obj F ≅ (whiskeringRight _ _ _).obj F ⋙ J.plusFunctor E := NatIso.ofComponents (fun _ => J.plusCompIso _ _) @fun _ _ _ => plusCompIso_whiskerRight _ _ _ @[reassoc (attr := simp)] theorem whiskerRight_toPlus_comp_plusCompIso_hom : whiskerRight (J.toPlus _) _ ≫ (J.plusCompIso F P).hom = J.toPlus _ := by ext dsimp [toPlus] simp only [ι_plusCompIso_hom, Functor.map_comp, Category.assoc] simp only [← Category.assoc] congr 1 dsimp only [diagram] -- Need to unfold `diagram` before `ext` applies. ext a rw [Category.assoc, diagramCompIso_hom_ι, ← F.map_comp] simp only [unop_op, limit.lift_π, Multifork.ofι_π_app, Functor.comp_obj, Functor.comp_map] @[simp] theorem toPlus_comp_plusCompIso_inv : J.toPlus _ ≫ (J.plusCompIso F P).inv = whiskerRight (J.toPlus _) _ := by simp [Iso.comp_inv_eq] theorem plusCompIso_inv_eq_plusLift (hP : Presheaf.IsSheaf J (J.plusObj P ⋙ F)) : (J.plusCompIso F P).inv = J.plusLift (whiskerRight (J.toPlus _) _) hP := by apply J.plusLift_unique simp end CategoryTheory.GrothendieckTopology
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Localization.lean
import Mathlib.CategoryTheory.Localization.Bousfield import Mathlib.CategoryTheory.Sites.Sheafification /-! # The sheaf category as a localized category In this file, it is shown that the category of sheaves `Sheaf J A` is a localization of the category `Presheaf J A` with respect to the class `J.W` of morphisms of presheaves which become isomorphisms after applying the sheafification functor. -/ namespace CategoryTheory open Localization variable {C : Type*} [Category C] (J : GrothendieckTopology C) {A : Type*} [Category A] namespace GrothendieckTopology /-- The class of morphisms of presheaves which become isomorphisms after sheafification. (See `GrothendieckTopology.W_iff`.) -/ abbrev W : MorphismProperty (Cᵒᵖ ⥤ A) := LeftBousfield.W (Presheaf.IsSheaf J) variable (A) in lemma W_eq_W_range_sheafToPresheaf_obj : J.W = LeftBousfield.W (· ∈ Set.range (sheafToPresheaf J A).obj) := by apply congr_arg ext P constructor · intro hP exact ⟨⟨P, hP⟩, rfl⟩ · rintro ⟨F, rfl⟩ exact F.cond lemma W_sheafToPresheaf_map_iff_isIso {F₁ F₂ : Sheaf J A} (φ : F₁ ⟶ F₂) : J.W ((sheafToPresheaf J A).map φ) ↔ IsIso φ := by rw [W_eq_W_range_sheafToPresheaf_obj, LeftBousfield.W_iff_isIso _ _ ⟨_, rfl⟩ ⟨_, rfl⟩, isIso_iff_of_reflects_iso] @[deprecated (since := "2025-07-27")] alias W_sheafToPreheaf_map_iff_isIso := W_sheafToPresheaf_map_iff_isIso section Adjunction variable {G : (Cᵒᵖ ⥤ A) ⥤ Sheaf J A} lemma W_adj_unit_app (adj : G ⊣ sheafToPresheaf J A) (P : Cᵒᵖ ⥤ A) : J.W (adj.unit.app P) := by rw [W_eq_W_range_sheafToPresheaf_obj] exact LeftBousfield.W_adj_unit_app adj P lemma W_iff_isIso_map_of_adjunction (adj : G ⊣ sheafToPresheaf J A) {P₁ P₂ : Cᵒᵖ ⥤ A} (f : P₁ ⟶ P₂) : J.W f ↔ IsIso (G.map f) := by rw [W_eq_W_range_sheafToPresheaf_obj] exact LeftBousfield.W_iff_isIso_map adj f lemma W_eq_inverseImage_isomorphisms_of_adjunction (adj : G ⊣ sheafToPresheaf J A) : J.W = (MorphismProperty.isomorphisms _).inverseImage G := by rw [W_eq_W_range_sheafToPresheaf_obj, LeftBousfield.W_eq_inverseImage_isomorphisms adj] end Adjunction section HasWeakSheafify variable [HasWeakSheafify J A] lemma W_toSheafify (P : Cᵒᵖ ⥤ A) : J.W (toSheafify J P) := J.W_adj_unit_app (sheafificationAdjunction J A) P lemma W_iff {P₁ P₂ : Cᵒᵖ ⥤ A} (f : P₁ ⟶ P₂) : J.W f ↔ IsIso ((presheafToSheaf J A).map f) := J.W_iff_isIso_map_of_adjunction (sheafificationAdjunction J A) f variable (A) in lemma W_eq_inverseImage_isomorphisms : J.W = (MorphismProperty.isomorphisms _).inverseImage (presheafToSheaf J A) := J.W_eq_inverseImage_isomorphisms_of_adjunction (sheafificationAdjunction J A) instance : (presheafToSheaf J A).IsLocalization J.W := by rw [W_eq_inverseImage_isomorphisms] exact (sheafificationAdjunction J A).isLocalization end HasWeakSheafify end GrothendieckTopology end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Sheafification.lean
import Mathlib.CategoryTheory.Adjunction.Unique import Mathlib.CategoryTheory.Adjunction.Reflective import Mathlib.CategoryTheory.Sites.Sheaf import Mathlib.CategoryTheory.Limits.Preserves.Finite /-! # Sheafification Given a site `(C, J)` we define a typeclass `HasSheafify J A` saying that the inclusion functor from `A`-valued sheaves on `C` to presheaves admits a left exact left adjoint (sheafification). Note: to access the `HasSheafify` instance for suitable concrete categories, import the file `Mathlib/CategoryTheory/Sites/LeftExact.lean`. -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory open Limits variable {C : Type u₁} [Category.{v₁} C] (J : GrothendieckTopology C) variable (A : Type u₂) [Category.{v₂} A] /-- A proposition saying that the inclusion functor from sheaves to presheaves admits a left adjoint. -/ abbrev HasWeakSheafify : Prop := (sheafToPresheaf J A).IsRightAdjoint /-- `HasSheafify` means that the inclusion functor from sheaves to presheaves admits a left exact left adjoint (sheafification). Given a functor, preserving finite limits, `F : (Cᵒᵖ ⥤ A) ⥤ Sheaf J A` and an adjunction `adj : F ⊣ sheafToPresheaf J A`, use `HasSheafify.mk'` to construct a `HasSheafify` instance. -/ class HasSheafify : Prop where isRightAdjoint : HasWeakSheafify J A isLeftExact : PreservesFiniteLimits ((sheafToPresheaf J A).leftAdjoint) instance [HasSheafify J A] : HasWeakSheafify J A := HasSheafify.isRightAdjoint noncomputable section instance [HasSheafify J A] : PreservesFiniteLimits ((sheafToPresheaf J A).leftAdjoint) := HasSheafify.isLeftExact theorem HasSheafify.mk' {F : (Cᵒᵖ ⥤ A) ⥤ Sheaf J A} (adj : F ⊣ sheafToPresheaf J A) [PreservesFiniteLimits F] : HasSheafify J A where isRightAdjoint := ⟨F, ⟨adj⟩⟩ isLeftExact := ⟨by have : (sheafToPresheaf J A).IsRightAdjoint := ⟨_, ⟨adj⟩⟩ exact fun _ _ _ ↦ preservesLimitsOfShape_of_natIso (adj.leftAdjointUniq (Adjunction.ofIsRightAdjoint (sheafToPresheaf J A)))⟩ /-- The sheafification functor, left adjoint to the inclusion. -/ def presheafToSheaf [HasWeakSheafify J A] : (Cᵒᵖ ⥤ A) ⥤ Sheaf J A := (sheafToPresheaf J A).leftAdjoint instance [HasSheafify J A] : PreservesFiniteLimits (presheafToSheaf J A) := HasSheafify.isLeftExact /-- The sheafification-inclusion adjunction. -/ def sheafificationAdjunction [HasWeakSheafify J A] : presheafToSheaf J A ⊣ sheafToPresheaf J A := Adjunction.ofIsRightAdjoint _ instance [HasWeakSheafify J A] : (presheafToSheaf J A).IsLeftAdjoint := ⟨_, ⟨sheafificationAdjunction J A⟩⟩ instance [HasWeakSheafify J A] : Reflective (sheafToPresheaf J A) where L := presheafToSheaf J A adj := sheafificationAdjunction _ _ instance [HasSheafify J A] : PreservesFiniteLimits (reflector (sheafToPresheaf J A)) := inferInstanceAs (PreservesFiniteLimits (presheafToSheaf _ _)) end variable {D : Type*} [Category D] [HasWeakSheafify J D] /-- The sheafification of a presheaf `P`. -/ noncomputable abbrev sheafify (P : Cᵒᵖ ⥤ D) : Cᵒᵖ ⥤ D := presheafToSheaf J D |>.obj P |>.val /-- The canonical map from `P` to its sheafification. -/ noncomputable abbrev toSheafify (P : Cᵒᵖ ⥤ D) : P ⟶ sheafify J P := sheafificationAdjunction J D |>.unit.app P @[simp] theorem sheafificationAdjunction_unit_app (P : Cᵒᵖ ⥤ D) : (sheafificationAdjunction J D).unit.app P = toSheafify J P := rfl /-- The canonical map on sheafifications induced by a morphism. -/ noncomputable abbrev sheafifyMap {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : sheafify J P ⟶ sheafify J Q := presheafToSheaf J D |>.map η |>.val @[simp] theorem sheafifyMap_id (P : Cᵒᵖ ⥤ D) : sheafifyMap J (𝟙 P) = 𝟙 (sheafify J P) := by simp [sheafifyMap, sheafify] @[simp] theorem sheafifyMap_comp {P Q R : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (γ : Q ⟶ R) : sheafifyMap J (η ≫ γ) = sheafifyMap J η ≫ sheafifyMap J γ := by simp [sheafifyMap, sheafify] @[reassoc (attr := simp)] theorem toSheafify_naturality {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : η ≫ toSheafify J _ = toSheafify J _ ≫ sheafifyMap J η := sheafificationAdjunction J D |>.unit.naturality η variable (D) /-- The sheafification of a presheaf `P`, as a functor. -/ noncomputable abbrev sheafification : (Cᵒᵖ ⥤ D) ⥤ Cᵒᵖ ⥤ D := presheafToSheaf J D ⋙ sheafToPresheaf J D theorem sheafification_obj (P : Cᵒᵖ ⥤ D) : (sheafification J D).obj P = sheafify J P := rfl theorem sheafification_map {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : (sheafification J D).map η = sheafifyMap J η := rfl /-- The canonical map from `P` to its sheafification, as a natural transformation. -/ noncomputable abbrev toSheafification : 𝟭 _ ⟶ sheafification J D := sheafificationAdjunction J D |>.unit theorem toSheafification_app (P : Cᵒᵖ ⥤ D) : (toSheafification J D).app P = toSheafify J P := rfl variable {D} theorem isIso_toSheafify {P : Cᵒᵖ ⥤ D} (hP : Presheaf.IsSheaf J P) : IsIso (toSheafify J P) := by refine ⟨(sheafificationAdjunction J D |>.counit.app ⟨P, hP⟩).val, ?_, ?_⟩ · change _ = (𝟙 (sheafToPresheaf J D ⋙ 𝟭 (Cᵒᵖ ⥤ D)) :).app ⟨P, hP⟩ rw [← sheafificationAdjunction J D |>.right_triangle] rfl · change (sheafToPresheaf _ _).map _ ≫ _ = _ change _ ≫ (sheafificationAdjunction J D).unit.app ((sheafToPresheaf J D).obj ⟨P, hP⟩) = _ rw [← (sheafificationAdjunction J D).inv_counit_map (X := ⟨P, hP⟩)] simp /-- If `P` is a sheaf, then `P` is isomorphic to `sheafify J P`. -/ noncomputable def isoSheafify {P : Cᵒᵖ ⥤ D} (hP : Presheaf.IsSheaf J P) : P ≅ sheafify J P := letI := isIso_toSheafify J hP asIso (toSheafify J P) @[simp] theorem isoSheafify_hom {P : Cᵒᵖ ⥤ D} (hP : Presheaf.IsSheaf J P) : (isoSheafify J hP).hom = toSheafify J P := rfl /-- Given a sheaf `Q` and a morphism `P ⟶ Q`, construct a morphism from `sheafify J P` to `Q`. -/ noncomputable def sheafifyLift {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (hQ : Presheaf.IsSheaf J Q) : sheafify J P ⟶ Q := (sheafificationAdjunction J D).homEquiv P ⟨Q, hQ⟩ |>.symm η |>.val @[simp] theorem sheafificationAdjunction_counit_app_val (P : Sheaf J D) : ((sheafificationAdjunction J D).counit.app P).val = sheafifyLift J (𝟙 P.val) P.cond := by unfold sheafifyLift rw [Adjunction.homEquiv_counit] simp @[reassoc (attr := simp)] theorem toSheafify_sheafifyLift {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (hQ : Presheaf.IsSheaf J Q) : toSheafify J P ≫ sheafifyLift J η hQ = η := by rw [toSheafify, sheafifyLift, Adjunction.homEquiv_counit] change _ ≫ (sheafToPresheaf J D).map _ ≫ _ = _ simp only [Adjunction.unit_naturality_assoc] change _ ≫ (sheafificationAdjunction J D).unit.app ((sheafToPresheaf J D).obj ⟨Q, hQ⟩) ≫ _ = _ change _ ≫ _ ≫ (sheafToPresheaf J D).map _ = _ rw [sheafificationAdjunction J D |>.right_triangle_components (Y := ⟨Q, hQ⟩)] simp theorem sheafifyLift_unique {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (hQ : Presheaf.IsSheaf J Q) (γ : sheafify J P ⟶ Q) : toSheafify J P ≫ γ = η → γ = sheafifyLift J η hQ := by intro h rw [toSheafify] at h rw [sheafifyLift] let γ' : (presheafToSheaf J D).obj P ⟶ ⟨Q, hQ⟩ := ⟨γ⟩ change γ'.val = _ rw [← Sheaf.Hom.ext_iff, ← Adjunction.homEquiv_apply_eq, Adjunction.homEquiv_unit] exact h @[simp] theorem isoSheafify_inv {P : Cᵒᵖ ⥤ D} (hP : Presheaf.IsSheaf J P) : (isoSheafify J hP).inv = sheafifyLift J (𝟙 _) hP := by apply sheafifyLift_unique simp [Iso.comp_inv_eq] theorem sheafify_hom_ext {P Q : Cᵒᵖ ⥤ D} (η γ : sheafify J P ⟶ Q) (hQ : Presheaf.IsSheaf J Q) (h : toSheafify J P ≫ η = toSheafify J P ≫ γ) : η = γ := by rw [sheafifyLift_unique J _ hQ _ h, ← h] exact (sheafifyLift_unique J _ hQ _ h.symm).symm @[reassoc (attr := simp)] theorem sheafifyMap_sheafifyLift {P Q R : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (γ : Q ⟶ R) (hR : Presheaf.IsSheaf J R) : sheafifyMap J η ≫ sheafifyLift J γ hR = sheafifyLift J (η ≫ γ) hR := by apply sheafifyLift_unique rw [← Category.assoc, ← toSheafify_naturality, Category.assoc, toSheafify_sheafifyLift] variable {J} /-- A sheaf `P` is isomorphic to its own sheafification. -/ @[simps] noncomputable def sheafificationIso (P : Sheaf J D) : P ≅ (presheafToSheaf J D).obj P.val where hom := ⟨(isoSheafify J P.2).hom⟩ inv := ⟨(isoSheafify J P.2).inv⟩ hom_inv_id := by ext1 apply (isoSheafify J P.2).hom_inv_id inv_hom_id := by ext1 apply (isoSheafify J P.2).inv_hom_id instance isIso_sheafificationAdjunction_counit (P : Sheaf J D) : IsIso ((sheafificationAdjunction J D).counit.app P) := isIso_of_fully_faithful (sheafToPresheaf J D) _ instance sheafification_reflective : IsIso (sheafificationAdjunction J D).counit := NatIso.isIso_of_isIso_app _ variable (J D) /-- The natural isomorphism `𝟭 (Sheaf J D) ≅ sheafToPresheaf J D ⋙ presheafToSheaf J D`. -/ @[simps!] noncomputable def sheafificationNatIso : 𝟭 (Sheaf J D) ≅ sheafToPresheaf J D ⋙ presheafToSheaf J D := NatIso.ofComponents (fun P => sheafificationIso P) (by cat_disch) end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/CartesianClosed.lean
import Mathlib.CategoryTheory.Closed.Ideal import Mathlib.CategoryTheory.Monoidal.Cartesian.FunctorCategory import Mathlib.CategoryTheory.Sites.CartesianMonoidal import Mathlib.CategoryTheory.Sites.Sheafification /-! # Sheaf categories are Cartesian closed ...if the underlying presheaf category is Cartesian closed, the target category has (chosen) finite products, and there exists a sheafification functor. -/ noncomputable section open CategoryTheory Presheaf variable {C : Type*} [Category C] (J : GrothendieckTopology C) (A : Type*) [Category A] instance [HasSheafify J A] [CartesianMonoidalCategory A] [CartesianClosed (Cᵒᵖ ⥤ A)] : CartesianClosed (Sheaf J A) := cartesianClosedOfReflective' (sheafToPresheaf _ _) { obj F := ⟨F.obj, (isSheaf_of_iso_iff F.2.choose_spec.some).1 (Sheaf.cond _)⟩ map f := ⟨f⟩ } (Iso.refl _)
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/ConstantSheaf.lean
import Mathlib.CategoryTheory.Sites.Sheafification import Mathlib.CategoryTheory.Sites.DenseSubsite.SheafEquiv /-! # The constant sheaf We define the constant sheaf functor (the sheafification of the constant presheaf) `constantSheaf : D ⥤ Sheaf J D` and prove that it is left adjoint to evaluation at a terminal object (see `constantSheafAdj`). We also define a predicate on sheaves, `Sheaf.IsConstant`, saying that a sheaf is in the essential image of the constant sheaf functor. ## Main results * `Sheaf.isConstant_iff_isIso_counit_app`: Provided that the constant sheaf functor is fully faithful, a sheaf is constant if and only if the counit of the constant sheaf adjunction applied to it is an isomorphism. * `Sheaf.isConstant_iff_of_equivalence` : The property of a sheaf of being constant is invariant under equivalence of sheaf categories. * `Sheaf.isConstant_iff_forget` : Given a "forgetful" functor `U : D ⥤ B` a sheaf `F : Sheaf J D` is constant if and only if the sheaf given by postcomposition with `U` is constant. -/ namespace CategoryTheory open Limits Opposite Category Functor Sheaf Adjunction variable {C : Type*} [Category C] (J : GrothendieckTopology C) variable (D : Type*) [Category D] /-- The constant presheaf functor is left adjoint to evaluation at a terminal object. -/ @[simps! unit_app counit_app_app] noncomputable def constantPresheafAdj {T : C} (hT : IsTerminal T) : Functor.const Cᵒᵖ ⊣ (evaluation Cᵒᵖ D).obj (op T) where unit := (Functor.constCompEvaluationObj D (op T)).hom counit := { app := fun F => { app := fun ⟨X⟩ => F.map (IsTerminal.from hT X).op naturality := fun _ _ _ => by simp only [Functor.comp_obj, Functor.const_obj_obj, Functor.id_obj, Functor.const_obj_map, Category.id_comp, ← Functor.map_comp] congr simp } naturality := by intros; ext; simp /- Note: `aesop` works but is kind of slow -/ } variable [HasWeakSheafify J D] /-- The functor which maps an object of `D` to the constant sheaf at that object, i.e. the sheafification of the constant presheaf. -/ noncomputable def constantSheaf : D ⥤ Sheaf J D := Functor.const Cᵒᵖ ⋙ (presheafToSheaf J D) /-- The constant sheaf functor is left adjoint to evaluation at a terminal object. -/ @[simps! counit_app] noncomputable def constantSheafAdj {T : C} (hT : IsTerminal T) : constantSheaf J D ⊣ (sheafSections J D).obj (op T) := (constantPresheafAdj D hT).comp (sheafificationAdjunction J D) variable {D} namespace Sheaf /-- A sheaf is constant if it is in the essential image of the constant sheaf functor. -/ class IsConstant (F : Sheaf J D) : Prop where mem_essImage : (constantSheaf J D).essImage F lemma mem_essImage_of_isConstant (F : Sheaf J D) [IsConstant J F] : (constantSheaf J D).essImage F := IsConstant.mem_essImage lemma isConstant_congr {F G : Sheaf J D} (i : F ≅ G) [IsConstant J F] : IsConstant J G where mem_essImage := essImage.ofIso i F.mem_essImage_of_isConstant lemma isConstant_of_iso {F : Sheaf J D} {X : D} (i : F ≅ (constantSheaf J D).obj X) : IsConstant J F := ⟨_, ⟨i.symm⟩⟩ lemma isConstant_iff_mem_essImage {L : D ⥤ Sheaf J D} {T : C} (hT : IsTerminal T) (adj : L ⊣ (sheafSections J D).obj ⟨T⟩) (F : Sheaf J D) : IsConstant J F ↔ L.essImage F := by rw [essImage_eq_of_natIso (adj.leftAdjointUniq (constantSheafAdj J D hT))] exact ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ lemma isConstant_of_isIso_counit_app (F : Sheaf J D) [HasTerminal C] [IsIso <| (constantSheafAdj J D terminalIsTerminal).counit.app F] : IsConstant J F where mem_essImage := ⟨_, ⟨asIso <| (constantSheafAdj J D terminalIsTerminal).counit.app F⟩⟩ instance [(constantSheaf J D).Faithful] [(constantSheaf J D).Full] (F : Sheaf J D) [IsConstant J F] {T : C} (hT : IsTerminal T) : IsIso ((constantSheafAdj J D hT).counit.app F) := by rw [isIso_counit_app_iff_mem_essImage] exact F.mem_essImage_of_isConstant /-- If the constant sheaf functor is fully faithful, then a sheaf is constant if and only if the counit of the constant sheaf adjunction applied to it is an isomorphism. -/ lemma isConstant_iff_isIso_counit_app [(constantSheaf J D).Faithful] [(constantSheaf J D).Full] (F : Sheaf J D) {T : C} (hT : IsTerminal T) : IsConstant J F ↔ (IsIso <| (constantSheafAdj J D hT).counit.app F) := ⟨fun _ ↦ inferInstance, fun _ ↦ ⟨_, ⟨asIso <| (constantSheafAdj J D hT).counit.app F⟩⟩⟩ /-- A variant of `isConstant_iff_isIso_counit_app` for a general left adjoint to evaluation at a terminal object. -/ lemma isConstant_iff_isIso_counit_app' {L : D ⥤ Sheaf J D} {T : C} (hT : IsTerminal T) (adj : L ⊣ (sheafSections J D).obj ⟨T⟩) [L.Faithful] [L.Full] (F : Sheaf J D) : IsConstant J F ↔ IsIso (adj.counit.app F) := (isConstant_iff_mem_essImage J hT adj F).trans (isIso_counit_app_iff_mem_essImage adj).symm end Sheaf section Equivalence variable {C' : Type*} [Category C'] (K : GrothendieckTopology C') [HasWeakSheafify K D] variable (G : C ⥤ C') [∀ (X : (C')ᵒᵖ), HasLimitsOfShape (StructuredArrow X G.op) D] [G.IsDenseSubsite J K] {T : C} (hT : IsTerminal T) (hT' : IsTerminal (G.obj T)) open IsDenseSubsite variable (D) in /-- The constant sheaf functor commutes up to isomorphism the equivalence of sheaf categories induced by a dense subsite. -/ noncomputable def equivCommuteConstant : constantSheaf J D ⋙ (sheafEquiv G J K D).functor ≅ constantSheaf K D := ((constantSheafAdj J D hT).comp (sheafEquiv G J K D).toAdjunction).leftAdjointUniq (constantSheafAdj K D hT') variable (D) in /-- The constant sheaf functor commutes up to isomorphism the inverse equivalence of sheaf categories induced by a dense subsite. -/ noncomputable def equivCommuteConstant' : constantSheaf J D ≅ constantSheaf K D ⋙ (sheafEquiv G J K D).inverse := isoWhiskerLeft (constantSheaf J D) (sheafEquiv G J K D).unitIso ≪≫ isoWhiskerRight (equivCommuteConstant J D K G hT hT') (sheafEquiv G J K D).inverse /- TODO: find suitable assumptions for proving generalizations of `equivCommuteConstant` and `equivCommuteConstant'` above, to commute `constantSheaf` with pullback/pushforward of sheaves. -/ include hT hT' in /-- The property of a sheaf of being constant is invariant under equivalence of sheaf categories. -/ lemma Sheaf.isConstant_iff_of_equivalence (F : Sheaf K D) : ((sheafEquiv G J K D).inverse.obj F).IsConstant J ↔ IsConstant K F := by constructor · exact fun ⟨Y, ⟨i⟩⟩ ↦ ⟨_, ⟨(equivCommuteConstant J D K G hT hT').symm.app _ ≪≫ (sheafEquiv G J K D).functor.mapIso i ≪≫ (sheafEquiv G J K D).counitIso.app _⟩⟩ · exact fun ⟨Y, ⟨i⟩⟩ ↦ ⟨_, ⟨(equivCommuteConstant' J D K G hT hT').app _ ≪≫ (sheafEquiv G J K D).inverse.mapIso i⟩⟩ end Equivalence section Forget variable {B : Type*} [Category B] (U : D ⥤ B) [HasWeakSheafify J B] [J.PreservesSheafification U] [J.HasSheafCompose U] (F : Sheaf J D) /-- The constant sheaf functor commutes with `sheafCompose J U` up to isomorphism, provided that `U` preserves sheafification. -/ noncomputable def constantCommuteCompose : constantSheaf J D ⋙ sheafCompose J U ≅ U ⋙ constantSheaf J B := (isoWhiskerLeft (const Cᵒᵖ) (sheafComposeNatIso J U (sheafificationAdjunction J D) (sheafificationAdjunction J B)).symm) ≪≫ isoWhiskerRight (compConstIso _ _).symm _ lemma constantCommuteCompose_hom_app_val (X : D) : ((constantCommuteCompose J U).hom.app X).val = (sheafifyComposeIso J U ((const Cᵒᵖ).obj X)).inv ≫ sheafifyMap J (constComp Cᵒᵖ X U).hom := rfl /-- The counit of `constantSheafAdj` factors through the isomorphism `constantCommuteCompose`. -/ lemma constantSheafAdj_counit_w {T : C} (hT : IsTerminal T) : ((constantCommuteCompose J U).hom.app (F.val.obj ⟨T⟩)) ≫ ((constantSheafAdj J B hT).counit.app ((sheafCompose J U).obj F)) = ((sheafCompose J U).map ((constantSheafAdj J D hT).counit.app F)) := by apply Sheaf.hom_ext rw [comp_val, constantCommuteCompose_hom_app_val, assoc, Iso.inv_comp_eq] apply sheafify_hom_ext _ _ _ ((sheafCompose J U).obj F).cond ext x simp [NatTrans.comp_app] -- simp [NatTrans.comp_app] to unfold some definitions simp [← map_comp, ← NatTrans.comp_app] -- simp [← NatTrans.comp_app] to simplify some compositions lemma Sheaf.isConstant_of_forget [constantSheaf J D |>.Faithful] [constantSheaf J D |>.Full] [constantSheaf J B |>.Faithful] [constantSheaf J B |>.Full] [(sheafCompose J U).ReflectsIsomorphisms] [((sheafCompose J U).obj F).IsConstant J] {T : C} (hT : IsTerminal T) : F.IsConstant J := by have : IsIso ((sheafCompose J U).map ((constantSheafAdj J D hT).counit.app F)) := by rw [← constantSheafAdj_counit_w] infer_instance rw [F.isConstant_iff_isIso_counit_app (hT := hT)] exact isIso_of_reflects_iso _ (sheafCompose J U) instance [h : F.IsConstant J] : ((sheafCompose J U).obj F).IsConstant J := by obtain ⟨Y, ⟨i⟩⟩ := h exact ⟨U.obj Y, ⟨(fullyFaithfulSheafToPresheaf _ _).preimageIso (((sheafifyComposeIso J U ((const Cᵒᵖ).obj Y)).symm ≪≫ (presheafToSheaf J B ⋙ sheafToPresheaf J B).mapIso (constComp Cᵒᵖ Y U)).symm ≪≫ (sheafToPresheaf _ _).mapIso ((sheafCompose J U).mapIso i))⟩⟩ lemma Sheaf.isConstant_iff_forget [constantSheaf J D |>.Faithful] [constantSheaf J D |>.Full] [constantSheaf J B |>.Faithful] [constantSheaf J B |>.Full] [(sheafCompose J U).ReflectsIsomorphisms] {T : C} (hT : IsTerminal T) : F.IsConstant J ↔ ((sheafCompose J U).obj F).IsConstant J := ⟨fun _ ↦ inferInstance, fun _ ↦ Sheaf.isConstant_of_forget _ U F hT⟩ end Forget end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Pullback.lean
import Mathlib.CategoryTheory.Adjunction.Restrict import Mathlib.CategoryTheory.Functor.Flat import Mathlib.CategoryTheory.Sites.Continuous import Mathlib.CategoryTheory.Sites.LeftExact /-! # Pullback of sheaves ## Main definitions * `CategoryTheory.Functor.sheafPullback`: when `G : C ⥤ D` is a continuous functor between sites (for topologies `J` on `C` and `K` on `D`) such that the functor `G.sheafPushforwardContinuous A J K : Sheaf K A ⥤ Sheaf J A` has a left adjoint, this is the pullback functor defined as a chosen left adjoint. * `CategoryTheory.Functor.sheafAdjunctionContinuous`: the adjunction `G.sheafPullback A J K ⊣ G.sheafPushforwardContinuous A J K` when the functor `G` is continuous. In case `G` is representably flat, the pullback functor on sheaves commutes with finite limits: this is a morphism of sites in the sense of SGA 4 IV 4.9. -/ universe v₁ v₂ v₃ u₁ u₂ u₃ noncomputable section namespace CategoryTheory.Functor open Limits section GeneralUniverses variable {C : Type u₂} [Category.{v₂} C] {D : Type u₃} [Category.{v₃} D] (G : C ⥤ D) (A : Type u₁) [Category.{v₁} A] (J : GrothendieckTopology C) (K : GrothendieckTopology D) [Functor.IsContinuous.{v₁} G J K] section variable [(G.sheafPushforwardContinuous A J K).IsRightAdjoint] /-- The pullback functor `Sheaf J A ⥤ Sheaf K A` associated to a functor `G : C ⥤ D` in the same direction as `G`. -/ def sheafPullback : Sheaf J A ⥤ Sheaf K A := (G.sheafPushforwardContinuous A J K).leftAdjoint /-- The pullback functor is left adjoint to the pushforward functor. -/ def sheafAdjunctionContinuous : G.sheafPullback A J K ⊣ G.sheafPushforwardContinuous A J K := Adjunction.ofIsRightAdjoint (G.sheafPushforwardContinuous A J K) end namespace sheafPullbackConstruction variable [∀ (F : Cᵒᵖ ⥤ A), G.op.HasLeftKanExtension F] /-- Construction of the pullback of sheaves using a left Kan extension. -/ def sheafPullback [HasWeakSheafify K A] : Sheaf J A ⥤ Sheaf K A := sheafToPresheaf J A ⋙ G.op.lan ⋙ presheafToSheaf K A /-- The constructed `sheafPullback G A J K` is left adjoint to `G.sheafPushforwardContinuous A J K`. -/ def sheafAdjunctionContinuous [Functor.IsContinuous.{v₁} G J K] [HasWeakSheafify K A] : sheafPullback G A J K ⊣ G.sheafPushforwardContinuous A J K := ((G.op.lanAdjunction A).comp (sheafificationAdjunction K A)).restrictFullyFaithful (fullyFaithfulSheafToPresheaf J A) (Functor.FullyFaithful.id _) (Iso.refl _) (Iso.refl _) instance [HasWeakSheafify K A] : (G.sheafPushforwardContinuous A J K).IsRightAdjoint := (sheafAdjunctionContinuous G A J K).isRightAdjoint /-- The constructed pullback of sheaves is isomorphic to the abstract one. -/ def sheafPullbackIso [HasWeakSheafify K A] : Functor.sheafPullback G A J K ≅ sheafPullback G A J K := Adjunction.leftAdjointUniq (Functor.sheafAdjunctionContinuous G A J K) (sheafAdjunctionContinuous G A J K) variable [RepresentablyFlat G] [HasSheafify K A] [HasSheafify J A] [PreservesFiniteLimits (G.op.lan : (_ ⥤ _ ⥤ A))] instance : PreservesFiniteLimits (sheafPullback G A J K) := by have : PreservesFiniteLimits (G.op.lan ⋙ presheafToSheaf K A) := comp_preservesFiniteLimits _ _ apply comp_preservesFiniteLimits instance preservesFiniteLimits : PreservesFiniteLimits (Functor.sheafPullback G A J K) := preservesFiniteLimits_of_natIso (sheafPullbackIso G A J K).symm end sheafPullbackConstruction end GeneralUniverses namespace SmallCategories variable {C : Type v₁} [SmallCategory C] {D : Type v₁} [SmallCategory D] (G : C ⥤ D) (A : Type u₁) [Category.{v₁} A] (J : GrothendieckTopology C) (K : GrothendieckTopology D) -- The favourable assumptions under which we have sheafification variable {FA : A → A → Type*} {CA : A → Type v₁} [∀ X Y, FunLike (FA X Y) (CA X) (CA Y)] variable [ConcreteCategory.{v₁} A FA] [PreservesLimits (forget A)] [HasColimits A] [HasLimits A] [PreservesFilteredColimits (forget A)] [(forget A).ReflectsIsomorphisms] [Functor.IsContinuous.{v₁} G J K] example : (G.sheafPushforwardContinuous A J K).IsRightAdjoint := inferInstance attribute [local instance] reflectsLimits_of_reflectsIsomorphisms in instance [RepresentablyFlat G] : PreservesFiniteLimits (G.sheafPullback A J K) := by apply sheafPullbackConstruction.preservesFiniteLimits end SmallCategories end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/CoversTop.lean
import Mathlib.CategoryTheory.Sites.Sheaf /-! Objects which cover the terminal object In this file, given a site `(C, J)`, we introduce the notion of a family of objects `Y : I → C` which "cover the final object": this means that for all `X : C`, the sieve `Sieve.ofObjects Y X` is covering for `J`. When there is a terminal object `X : C`, then `J.CoversTop Y` holds iff `Sieve.ofObjects Y X` is covering for `J`. We introduce a notion of compatible family of elements on objects `Y` and obtain `Presheaf.FamilyOfElementsOnObjects.IsCompatible.existsUnique_section` which asserts that if a presheaf of types is a sheaf, then any compatible family of elements on objects `Y` which cover the final object extends as a section of this presheaf. -/ universe w v' v u' u namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) {A : Type u'} [Category.{v'} A] namespace GrothendieckTopology /-- A family of objects `Y : I → C` "covers the final object" if for all `X : C`, the sieve `ofObjects Y X` is a covering sieve. -/ def CoversTop {I : Type*} (Y : I → C) : Prop := ∀ (X : C), Sieve.ofObjects Y X ∈ J X lemma coversTop_iff_of_isTerminal (X : C) (hX : IsTerminal X) {I : Type*} (Y : I → C) : J.CoversTop Y ↔ Sieve.ofObjects Y X ∈ J X := by constructor · tauto · intro h W apply J.superset_covering _ (J.pullback_stable (hX.from W) h) rintro T a ⟨i, ⟨b⟩⟩ exact ⟨i, ⟨b⟩⟩ namespace CoversTop variable {J} variable {I : Type*} {Y : I → C} (hY : J.CoversTop Y) include hY /-- The cover of any object `W : C` attached to a family of objects `Y` that satisfy `J.CoversTop Y` -/ abbrev cover (W : C) : Cover J W := ⟨Sieve.ofObjects Y W, hY W⟩ lemma ext (F : Sheaf J A) {c : Cone F.1} (hc : IsLimit c) {X : A} {f g : X ⟶ c.pt} (h : ∀ (i : I), f ≫ c.π.app (Opposite.op (Y i)) = g ≫ c.π.app (Opposite.op (Y i))) : f = g := by refine hc.hom_ext (fun Z => F.2.hom_ext (hY.cover Z.unop) _ _ ?_) rintro ⟨W, a, ⟨i, ⟨b⟩⟩⟩ simpa using h i =≫ F.1.map b.op lemma sections_ext (F : Sheaf J (Type _)) {x y : F.1.sections} (h : ∀ (i : I), x.1 (Opposite.op (Y i)) = y.1 (Opposite.op (Y i))) : x = y := by ext W apply (((isSheaf_iff_isSheaf_of_type _ _).1 F.2).isSeparated _ (hY W.unop)).ext rintro T a ⟨i, ⟨b⟩⟩ simpa using congr_arg (F.1.map b.op) (h i) end CoversTop end GrothendieckTopology namespace Presheaf variable (F : Cᵒᵖ ⥤ Type w) {I : Type*} (Y : I → C) /-- A family of elements of a presheaf of types `F` indexed by a family of objects `Y : I → C` consists of the data of an element in `F.obj (Opposite.op (Y i))` for all `i`. -/ def FamilyOfElementsOnObjects := ∀ (i : I), F.obj (Opposite.op (Y i)) namespace FamilyOfElementsOnObjects variable {F Y} variable (x : FamilyOfElementsOnObjects F Y) /-- `x : FamilyOfElementsOnObjects F Y` is compatible if for any object `Z` such that there exists a morphism `f : Z → Y i`, then the pullback of `x i` by `f` is independent of `f` and `i`. -/ def IsCompatible (x : FamilyOfElementsOnObjects F Y) : Prop := ∀ (Z : C) (i j : I) (f : Z ⟶ Y i) (g : Z ⟶ Y j), F.map f.op (x i) = F.map g.op (x j) /-- A family of elements indexed by `Sieve.ofObjects Y X` that is induced by `x : FamilyOfElementsOnObjects F Y`. See the equational lemma `IsCompatible.familyOfElements_apply` which holds under the assumption `x.IsCompatible`. -/ noncomputable def familyOfElements (X : C) : Presieve.FamilyOfElements F (Sieve.ofObjects Y X).arrows := fun _ _ hf => F.map hf.choose_spec.some.op (x _) namespace IsCompatible variable {x} lemma familyOfElements_apply (hx : x.IsCompatible) {X Z : C} (f : Z ⟶ X) (i : I) (φ : Z ⟶ Y i) : familyOfElements x X f ⟨i, ⟨φ⟩⟩ = F.map φ.op (x i) := by apply hx lemma familyOfElements_isCompatible (hx : x.IsCompatible) (X : C) : (familyOfElements x X).Compatible := by intro Y₁ Y₂ Z g₁ g₂ f₁ f₂ ⟨i₁, ⟨φ₁⟩⟩ ⟨i₂, ⟨φ₂⟩⟩ _ simpa [hx.familyOfElements_apply f₁ i₁ φ₁, hx.familyOfElements_apply f₂ i₂ φ₂] using hx Z i₁ i₂ (g₁ ≫ φ₁) (g₂ ≫ φ₂) variable {J} lemma existsUnique_section (hx : x.IsCompatible) (hY : J.CoversTop Y) (hF : IsSheaf J F) : ∃! (s : F.sections), ∀ (i : I), s.1 (Opposite.op (Y i)) = x i := by have H := (isSheaf_iff_isSheaf_of_type _ _).1 hF apply existsUnique_of_exists_of_unique · let s := fun (X : C) => (H _ (hY X)).amalgamate _ (hx.familyOfElements_isCompatible X) have hs : ∀ {X : C} (i : I) (f : X ⟶ Y i), s X = F.map f.op (x i) := fun {X} i f => by have h := Presieve.IsSheafFor.valid_glue (H _ (hY X)) (hx.familyOfElements_isCompatible _) (𝟙 _) ⟨i, ⟨f⟩⟩ simp only [op_id, F.map_id, types_id_apply] at h exact h.trans (hx.familyOfElements_apply _ _ _) have hs' : ∀ {W X : C} (a : W ⟶ X) (i : I) (_ : W ⟶ Y i), F.map a.op (s X) = s W := by intro W X a i b rw [hs i b] exact (Presieve.IsSheafFor.valid_glue (H _ (hY X)) (hx.familyOfElements_isCompatible _) a ⟨i, ⟨b⟩⟩).trans (familyOfElements_apply hx _ _ _) refine ⟨⟨fun X => s X.unop, ?_⟩, fun i => (hs i (𝟙 (Y i))).trans (by simp)⟩ rintro ⟨Y₁⟩ ⟨Y₂⟩ ⟨f : Y₂ ⟶ Y₁⟩ change F.map f.op (s Y₁) = s Y₂ apply (H.isSeparated _ (hY Y₂)).ext rintro Z φ ⟨i, ⟨g⟩⟩ rw [hs' φ i g, ← hs' (φ ≫ f) i g, op_comp, F.map_comp] rfl · intro y₁ y₂ hy₁ hy₂ exact hY.sections_ext ⟨F, hF⟩ (fun i => by rw [hy₁, hy₂]) variable (hx : x.IsCompatible) (hY : J.CoversTop Y) (hF : IsSheaf J F) /-- The section of a sheaf of types which lifts a compatible family of elements indexed by objects which cover the terminal object. -/ noncomputable def section_ : F.sections := (hx.existsUnique_section hY hF).choose @[simp] lemma section_apply (i : I) : (hx.section_ hY hF).1 (Opposite.op (Y i)) = x i := (hx.existsUnique_section hY hF).choose_spec.1 i end IsCompatible end FamilyOfElementsOnObjects end Presheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/MorphismProperty.lean
import Mathlib.CategoryTheory.MorphismProperty.Limits import Mathlib.CategoryTheory.Sites.Pretopology import Mathlib.CategoryTheory.Sites.Coverage import Mathlib.CategoryTheory.Sites.Hypercover.Zero /-! # The site induced by a morphism property Let `C` be a category with pullbacks and `P` be a multiplicative morphism property which is stable under base change. Then `P` induces a pretopology, where coverings are given by presieves whose elements satisfy `P`. Standard examples of pretopologies in algebraic geometry, such as the étale site, are obtained from this construction by intersecting with the pretopology of surjective families. -/ universe w namespace CategoryTheory open Limits variable {C : Type*} [Category C] namespace MorphismProperty variable {P Q : MorphismProperty C} /-- This is the precoverage on `C` where covering presieves are those where every morphism satisfies `P`. -/ def precoverage (P : MorphismProperty C) : Precoverage C where coverings X S := ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → P f @[simp] lemma ofArrows_mem_precoverage {X : C} {ι : Type*} {Y : ι → C} {f : ∀ i, Y i ⟶ X} : .ofArrows Y f ∈ precoverage P X ↔ ∀ i, P (f i) := ⟨fun h i ↦ h ⟨i⟩, fun h _ g ⟨i⟩ ↦ h i⟩ instance [P.ContainsIdentities] [P.RespectsIso] : P.precoverage.HasIsos where mem_coverings_of_isIso f _ _ _ := fun ⟨⟩ ↦ P.of_isIso f instance [P.IsStableUnderBaseChange] : P.precoverage.IsStableUnderBaseChange where mem_coverings_of_isPullback {ι} S X f hf T g W p₁ p₂ h Z g hg := by obtain ⟨i⟩ := hg exact P.of_isPullback (h i).flip (hf ⟨i⟩) instance [P.IsStableUnderComposition] : P.precoverage.IsStableUnderComposition where comp_mem_coverings {ι} S X f hf σ Y g hg Z p := by intro ⟨i⟩ exact P.comp_mem _ _ (hg _ ⟨i.2⟩) (hf ⟨i.1⟩) instance : Precoverage.Small.{w} P.precoverage where zeroHypercoverSmall E := by constructor use PEmpty, PEmpty.elim simp lemma precoverage_monotone (hPQ : P ≤ Q) : precoverage P ≤ precoverage Q := fun _ _ hR _ _ hg ↦ hPQ _ (hR hg) variable (P Q) in lemma precoverage_inf : precoverage (P ⊓ Q) = precoverage P ⊓ precoverage Q := by ext X R exact ⟨fun hS ↦ ⟨fun _ _ hf ↦ (hS hf).left, fun _ _ hf ↦ (hS hf).right⟩, fun h ↦ fun _ _ hf ↦ ⟨h.left hf, h.right hf⟩⟩ /-- If `P` is stable under base change, this is the coverage on `C` where covering presieves are those where every morphism satisfies `P`. -/ @[simps toPrecoverage] def coverage (P : MorphismProperty C) [P.IsStableUnderBaseChange] [P.HasPullbacks] : Coverage C where __ := precoverage P pullback X Y f S hS := by have : S.HasPullbacks f := ⟨fun {W} h hh ↦ P.hasPullback _ (hS hh)⟩ refine ⟨S.pullbackArrows f, ?_, .pullbackArrows f S⟩ intro Z g ⟨W, a, h⟩ have := S.hasPullback f h exact P.pullback_snd _ _ (hS h) /-- If `P` is stable under base change, it induces a Grothendieck topology: the one associated to `coverage P`. -/ abbrev grothendieckTopology (P : MorphismProperty C) [P.IsStableUnderBaseChange] [P.HasPullbacks] : GrothendieckTopology C := P.coverage.toGrothendieck section HasPullbacks variable [P.IsStableUnderBaseChange] [HasPullbacks C] /-- If `P` is a multiplicative morphism property which is stable under base change on a category `C` with pullbacks, then `P` induces a pretopology, where coverings are given by presieves whose elements satisfy `P`. -/ @[simps! toPrecoverage] def pretopology (P : MorphismProperty C) [P.IsMultiplicative] [P.IsStableUnderBaseChange] : Pretopology C := (precoverage P).toPretopology /-- If `P` is also multiplicative, the coverage induced by `P` is the pretopology induced by `P`. -/ lemma coverage_eq_toCoverage_pretopology [P.IsMultiplicative] : P.coverage = P.pretopology.toCoverage := rfl /-- If `P` is also multiplicative, the topology induced by `P` is the topology induced by the pretopology induced by `P`. -/ lemma grothendieckTopology_eq_toGrothendieck_pretopology [P.IsMultiplicative] : P.grothendieckTopology = P.pretopology.toGrothendieck := by rw [grothendieckTopology, coverage_eq_toCoverage_pretopology, Pretopology.toGrothendieck_toCoverage] section variable {P Q : MorphismProperty C} [P.IsMultiplicative] [P.IsStableUnderBaseChange] [Q.IsMultiplicative] [Q.IsStableUnderBaseChange] lemma pretopology_monotone (hPQ : P ≤ Q) : P.pretopology ≤ Q.pretopology := precoverage_monotone hPQ @[deprecated (since := "2025-08-28")] alias pretopology_le := pretopology_monotone variable (P Q) in lemma pretopology_inf : (P ⊓ Q).pretopology = P.pretopology ⊓ Q.pretopology := by ext : 1 simp only [pretopology_toPrecoverage, precoverage_inf] rfl end end HasPullbacks end CategoryTheory.MorphismProperty
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Adjunction.lean
import Mathlib.CategoryTheory.Adjunction.Restrict import Mathlib.CategoryTheory.Adjunction.Whiskering import Mathlib.CategoryTheory.Sites.PreservesSheafification /-! In this file, we show that an adjunction `G ⊣ F` induces an adjunction between categories of sheaves. We also show that `G` preserves sheafification. -/ namespace CategoryTheory open GrothendieckTopology Limits Opposite Functor universe v₁ v₂ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] (J : GrothendieckTopology C) variable {D : Type u₂} [Category.{v₂} D] variable {E : Type*} [Category E] variable {F : D ⥤ E} {G : E ⥤ D} /-- The forgetful functor from `Sheaf J D` to sheaves of types, for a concrete category `D` whose forgetful functor preserves the correct limits. -/ abbrev sheafForget [HasForget D] [HasSheafCompose J (forget D)] : Sheaf J D ⥤ Sheaf J (Type _) := sheafCompose J (forget D) namespace Sheaf noncomputable section /-- An adjunction `adj : G ⊣ F` with `F : D ⥤ E` and `G : E ⥤ D` induces an adjunction between `Sheaf J D` and `Sheaf J E`, in contexts where one can sheafify `D`-valued presheaves, and postcomposing with `F` preserves the property of being a sheaf. -/ def adjunction [HasWeakSheafify J D] [HasSheafCompose J F] (adj : G ⊣ F) : composeAndSheafify J G ⊣ sheafCompose J F := Adjunction.restrictFullyFaithful ((adj.whiskerRight Cᵒᵖ).comp (sheafificationAdjunction J D)) (fullyFaithfulSheafToPresheaf J E) (Functor.FullyFaithful.id _) (Iso.refl _) (Iso.refl _) @[simp] lemma adjunction_unit_app_val [HasWeakSheafify J D] [HasSheafCompose J F] (adj : G ⊣ F) (X : Sheaf J E) : ((adjunction J adj).unit.app X).val = (adj.whiskerRight Cᵒᵖ).unit.app _ ≫ whiskerRight (toSheafify J (X.val ⋙ G)) F := by change (sheafToPresheaf _ _).map ((adjunction J adj).unit.app X) = _ simp only [Functor.id_obj, Functor.comp_obj, whiskeringRight_obj_obj, adjunction, Adjunction.map_restrictFullyFaithful_unit_app, Adjunction.comp_unit_app, sheafificationAdjunction_unit_app, whiskeringRight_obj_map, Iso.refl_hom, NatTrans.id_app, Functor.comp_map, Functor.map_id, whiskerRight_id', Category.comp_id] rfl @[simp] lemma adjunction_counit_app_val [HasWeakSheafify J D] [HasSheafCompose J F] (adj : G ⊣ F) (Y : Sheaf J D) : ((adjunction J adj).counit.app Y).val = sheafifyLift J (((adj.whiskerRight Cᵒᵖ).counit.app Y.val)) Y.cond := by change ((𝟭 (Sheaf _ _)).map ((adjunction J adj).counit.app Y)).val = _ simp only [Functor.comp_obj, sheafToPresheaf_obj, sheafCompose_obj_val, whiskeringRight_obj_obj, adjunction, Adjunction.map_restrictFullyFaithful_counit_app, Iso.refl_inv, NatTrans.id_app, Functor.comp_map, whiskeringRight_obj_map, Adjunction.comp_counit_app, comp_val, sheafificationAdjunction_counit_app_val, sheafifyMap_sheafifyLift, Functor.id_obj, whiskerRight_id', Category.comp_id, Category.id_comp] instance [HasWeakSheafify J D] [F.IsRightAdjoint] : (sheafCompose J F).IsRightAdjoint := (adjunction J (Adjunction.ofIsRightAdjoint F)).isRightAdjoint instance [HasWeakSheafify J D] [G.IsLeftAdjoint] : (composeAndSheafify J G).IsLeftAdjoint := (adjunction J (Adjunction.ofIsLeftAdjoint G)).isLeftAdjoint lemma preservesSheafification_of_adjunction (adj : G ⊣ F) : J.PreservesSheafification G where le P Q f hf := by have := adj.isRightAdjoint rw [MorphismProperty.inverseImage_iff] dsimp intro R hR rw [← ((adj.whiskerRight Cᵒᵖ).homEquiv P R).comp_bijective] convert (((adj.whiskerRight Cᵒᵖ).homEquiv Q R).trans (hf.homEquiv (R ⋙ F) ((sheafCompose J F).obj ⟨R, hR⟩).cond)).bijective ext g X -- The rest of this proof was -- `dsimp [Adjunction.whiskerRight, Adjunction.mkOfUnitCounit]; simp` before https://github.com/leanprover-community/mathlib4/pull/16317. dsimp rw [← NatTrans.comp_app] congr exact Adjunction.homEquiv_naturality_left _ _ _ instance [G.IsLeftAdjoint] : J.PreservesSheafification G := preservesSheafification_of_adjunction J (Adjunction.ofIsLeftAdjoint G) section ForgetToType variable [HasWeakSheafify J D] [HasForget D] [HasSheafCompose J (forget D)] example [(forget D).IsRightAdjoint] : (sheafForget.{_, _, _, _, max u₁ v₁} (D := D) J).IsRightAdjoint := by infer_instance end ForgetToType end end Sheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Continuous.lean
import Mathlib.CategoryTheory.Sites.Hypercover.IsSheaf /-! # Continuous functors between sites. We define the notion of continuous functor between sites: these are functors `F` such that the precomposition with `F.op` preserves sheaves of types (and actually sheaves in any category). ## Main definitions * `Functor.IsContinuous`: a functor between sites is continuous if the precomposition with this functor preserves sheaves with values in the category `Type t` for a certain auxiliary universe `t`. * `Functor.sheafPushforwardContinuous`: the induced functor `Sheaf K A ⥤ Sheaf J A` for a continuous functor `G : (C, J) ⥤ (D, K)`. In case this is part of a morphism of sites, this would be understood as the pushforward functor even though it goes in the opposite direction as the functor `G`. (Here, the auxiliary universe `t` in the assumption that `G` is continuous is the one such that morphisms in the category `A` are in `Type t`.) * `Functor.PreservesOneHypercovers`: a type-class expressing that a functor preserves 1-hypercovers of a certain size ## Main result - `Functor.isContinuous_of_preservesOneHypercovers`: if the topology on `C` is generated by 1-hypercovers of size `w` and that `F : C ⥤ D` preserves 1-hypercovers of size `w`, then `F` is continuous (for any auxiliary universe parameter `t`). This is an instance for `w = max u₁ v₁` when `C : Type u₁` and `[Category.{v₁} C]` ## References * https://stacks.math.columbia.edu/tag/00WU -/ universe w t v₁ v₂ v₃ u₁ u₂ u₃ u namespace CategoryTheory open Limits variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] {E : Type u₃} [Category.{v₃} E] namespace PreOneHypercover variable {X : C} (E : PreOneHypercover X) (F : C ⥤ D) /-- The image of a 1-pre-hypercover by a functor. -/ @[simps] def map : PreOneHypercover (F.obj X) where I₀ := E.I₀ X i := F.obj (E.X i) f i := F.map (E.f i) I₁ := E.I₁ Y _ _ j := F.obj (E.Y j) p₁ _ _ j := F.map (E.p₁ j) p₂ _ _ j := F.map (E.p₂ j) w _ _ j := by simpa using F.congr_map (E.w j) /-- If `F : C ⥤ D`, `P : Dᵒᵖ ⥤ A` and `E` is a 1-pre-hypercover of an object of `X`, then `(E.map F).multifork P` is a limit iff `E.multifork (F.op ⋙ P)` is a limit. -/ def isLimitMapMultiforkEquiv {A : Type u} [Category.{t} A] (P : Dᵒᵖ ⥤ A) : IsLimit ((E.map F).multifork P) ≃ IsLimit (E.multifork (F.op ⋙ P)) := by rfl end PreOneHypercover namespace GrothendieckTopology namespace OneHypercover variable {J : GrothendieckTopology C} {X : C} (E : J.OneHypercover X) /-- A 1-hypercover in `C` is preserved by a functor `F : C ⥤ D` if the mapped 1-pre-hypercover in `D` is a 1-hypercover for the given topology on `D`. -/ class IsPreservedBy (F : C ⥤ D) (K : GrothendieckTopology D) : Prop where mem₀ : (E.toPreOneHypercover.map F).sieve₀ ∈ K (F.obj X) mem₁ (i₁ i₂ : E.I₀) ⦃W : D⦄ (p₁ : W ⟶ F.obj (E.X i₁)) (p₂ : W ⟶ F.obj (E.X i₂)) (w : p₁ ≫ F.map (E.f i₁) = p₂ ≫ F.map (E.f i₂)) : (E.toPreOneHypercover.map F).sieve₁ p₁ p₂ ∈ K W /-- Given a 1-hypercover `E : J.OneHypercover X` of an object of `C`, a functor `F : C ⥤ D` such that `E.IsPreservedBy F K` for a Grothendieck topology `K` on `D`, this is the image of `E` by `F`, as a 1-hypercover of `F.obj X` for `K`. -/ @[simps! toPreOneHypercover] def map (F : C ⥤ D) (K : GrothendieckTopology D) [E.IsPreservedBy F K] : K.OneHypercover (F.obj X) where toPreOneHypercover := E.toPreOneHypercover.map F mem₀ := IsPreservedBy.mem₀ mem₁ _ _ _ _ _ h := IsPreservedBy.mem₁ _ _ _ _ h instance : E.IsPreservedBy (𝟭 C) J where mem₀ := E.mem₀ mem₁ := E.mem₁ end OneHypercover end GrothendieckTopology namespace Functor variable (F F' : C ⥤ D) (τ : F ⟶ F') (e : F ≅ F') (G : D ⥤ E) {F'' : C ⥤ C} (eF'' : F'' ≅ 𝟭 C) {FG : C ⥤ E} (eFG : F ⋙ G ≅ FG) {A : Type u} [Category.{t} A] (J : GrothendieckTopology C) (K : GrothendieckTopology D) (L : GrothendieckTopology E) /-- The condition that a functor `F : C ⥤ D` sends 1-hypercovers for `J : GrothendieckTopology C` to 1-hypercovers for `K : GrothendieckTopology D`. -/ abbrev PreservesOneHypercovers := ∀ {X : C} (E : GrothendieckTopology.OneHypercover.{w} J X), E.IsPreservedBy F K /-- A functor `F` is continuous if the precomposition with `F.op` sends sheaves of `Type t` to sheaves. -/ class IsContinuous : Prop where op_comp_isSheaf_of_types (G : Sheaf K (Type t)) : Presieve.IsSheaf J (F.op ⋙ G.val) lemma op_comp_isSheaf_of_types [Functor.IsContinuous.{t} F J K] (G : Sheaf K (Type t)) : Presieve.IsSheaf J (F.op ⋙ G.val) := Functor.IsContinuous.op_comp_isSheaf_of_types _ lemma op_comp_isSheaf [Functor.IsContinuous.{t} F J K] (G : Sheaf K A) : Presheaf.IsSheaf J (F.op ⋙ G.val) := fun T => F.op_comp_isSheaf_of_types J K ⟨_, (isSheaf_iff_isSheaf_of_type _ _).2 (G.cond T)⟩ lemma isContinuous_of_iso {F₁ F₂ : C ⥤ D} (e : F₁ ≅ F₂) (J : GrothendieckTopology C) (K : GrothendieckTopology D) [Functor.IsContinuous.{t} F₁ J K] : Functor.IsContinuous.{t} F₂ J K where op_comp_isSheaf_of_types G := Presieve.isSheaf_iso J (isoWhiskerRight (NatIso.op e.symm) _) (F₁.op_comp_isSheaf_of_types J K G) instance isContinuous_id : Functor.IsContinuous.{w} (𝟭 C) J J where op_comp_isSheaf_of_types G := (isSheaf_iff_isSheaf_of_type _ _).1 G.2 lemma isContinuous_comp (F₁ : C ⥤ D) (F₂ : D ⥤ E) (J : GrothendieckTopology C) (K : GrothendieckTopology D) (L : GrothendieckTopology E) [Functor.IsContinuous.{t} F₁ J K] [Functor.IsContinuous.{t} F₂ K L] : Functor.IsContinuous.{t} (F₁ ⋙ F₂) J L where op_comp_isSheaf_of_types G := F₁.op_comp_isSheaf_of_types J K ⟨_,(isSheaf_iff_isSheaf_of_type _ _).2 (F₂.op_comp_isSheaf_of_types K L G)⟩ lemma isContinuous_comp' {F₁ : C ⥤ D} {F₂ : D ⥤ E} {F₁₂ : C ⥤ E} (e : F₁ ⋙ F₂ ≅ F₁₂) (J : GrothendieckTopology C) (K : GrothendieckTopology D) (L : GrothendieckTopology E) [Functor.IsContinuous.{t} F₁ J K] [Functor.IsContinuous.{t} F₂ K L] : Functor.IsContinuous.{t} F₁₂ J L := by have := Functor.isContinuous_comp F₁ F₂ J K L apply Functor.isContinuous_of_iso e section lemma op_comp_isSheaf_of_preservesOneHypercovers [PreservesOneHypercovers.{w} F J K] [GrothendieckTopology.IsGeneratedByOneHypercovers.{w} J] (P : Dᵒᵖ ⥤ A) (hP : Presheaf.IsSheaf K P) : Presheaf.IsSheaf J (F.op ⋙ P) := by rw [Presheaf.isSheaf_iff_of_isGeneratedByOneHypercovers.{w}] intro X E exact ⟨(E.toPreOneHypercover.isLimitMapMultiforkEquiv F P) ((E.map F K).isLimitMultifork ⟨P, hP⟩)⟩ lemma isContinuous_of_preservesOneHypercovers [PreservesOneHypercovers.{w} F J K] [GrothendieckTopology.IsGeneratedByOneHypercovers.{w} J] : IsContinuous.{t} F J K where op_comp_isSheaf_of_types := by rintro ⟨P, hP⟩ rw [← isSheaf_iff_isSheaf_of_type] exact F.op_comp_isSheaf_of_preservesOneHypercovers J K P hP end instance [PreservesOneHypercovers.{max u₁ v₁} F J K] : IsContinuous.{t} F J K := isContinuous_of_preservesOneHypercovers.{max u₁ v₁} F J K variable (A) variable [Functor.IsContinuous.{t} F J K] /-- The induced functor `Sheaf K A ⥤ Sheaf J A` given by `F.op ⋙ _` if `F` is a continuous functor. -/ @[simps!] def sheafPushforwardContinuous : Sheaf K A ⥤ Sheaf J A where obj ℱ := ⟨F.op ⋙ ℱ.val, F.op_comp_isSheaf J K ℱ⟩ map f := ⟨((whiskeringLeft _ _ _).obj F.op).map f.val⟩ /-- The functor `F.sheafPushforwardContinuous A J K : Sheaf K A ⥤ Sheaf J A` is induced by the precomposition with `F.op`. -/ @[simps!] def sheafPushforwardContinuousCompSheafToPresheafIso : F.sheafPushforwardContinuous A J K ⋙ sheafToPresheaf J A ≅ sheafToPresheaf K A ⋙ (whiskeringLeft _ _ _).obj F.op := Iso.refl _ /-- The functor `sheafPushforwardContinuous` corresponding to the identity functor identifies to the identity functor. -/ @[simps!] def sheafPushforwardContinuousId : sheafPushforwardContinuous (𝟭 C) A J J ≅ 𝟭 _ := Iso.refl _ /-- The composition of two pushforward functors on sheaves identifies to the pushforward for the composition of the two functors. -/ @[simps!] def sheafPushforwardContinuousComp [IsContinuous.{t} G K L] : letI := isContinuous_comp F G J K L sheafPushforwardContinuous G A K L ⋙ sheafPushforwardContinuous F A J K ≅ sheafPushforwardContinuous (F ⋙ G) A J L := Iso.refl _ variable {F F'} in /-- The action of a natural transformation on pushforward functors of sheaves. -/ @[simps] def sheafPushforwardContinuousNatTrans [IsContinuous.{t} F' J K] : sheafPushforwardContinuous F' A J K ⟶ sheafPushforwardContinuous F A J K where app M := ⟨whiskerRight (NatTrans.op τ) _⟩ variable {F F'} in /-- The action of a natural isomorphism on pushforward functors of sheaves. -/ @[simps] def sheafPushforwardContinuousIso [IsContinuous.{t} F' J K] : sheafPushforwardContinuous F A J K ≅ sheafPushforwardContinuous F' A J K where hom := sheafPushforwardContinuousNatTrans e.inv _ _ _ inv := sheafPushforwardContinuousNatTrans e.hom _ _ _ hom_inv_id := by ext; simp [← Functor.map_comp, ← op_comp] inv_hom_id := by ext; simp [← Functor.map_comp, ← op_comp] /-- If a continuous functor between sites is isomorphic to the identity functor, then the corresponding pushforward functor on sheaves identifies to the identity functor. -/ @[simps!] def sheafPushforwardContinuousId' [IsContinuous.{t} F'' J J] : sheafPushforwardContinuous F'' A J J ≅ 𝟭 _ := sheafPushforwardContinuousIso eF'' _ _ _ ≪≫ sheafPushforwardContinuousId _ _ variable {F G} in /-- When we have an isomorphism `F ⋙ G ≅ FG` between continuous functors between sites, the composition of the pushforward functors for `G` and `F` identifies to the pushforward functor for `FG`. -/ @[simps!] def sheafPushforwardContinuousComp' [IsContinuous.{t} G K L] [IsContinuous.{t} FG J L] : sheafPushforwardContinuous G A K L ⋙ sheafPushforwardContinuous F A J K ≅ sheafPushforwardContinuous FG A J L := letI := isContinuous_comp F G J K L sheafPushforwardContinuousComp _ _ _ _ _ _ ≪≫ sheafPushforwardContinuousIso eFG _ _ _ end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/PreservesSheafification.lean
import Mathlib.CategoryTheory.Sites.Localization import Mathlib.CategoryTheory.Sites.CompatibleSheafification import Mathlib.CategoryTheory.Sites.Whiskering import Mathlib.CategoryTheory.Sites.Sheafification /-! # Functors which preserve sheafification In this file, given a Grothendieck topology `J` on `C` and `F : A ⥤ B`, we define a type class `J.PreservesSheafification F`. We say that `F` preserves the sheafification if whenever a morphism of presheaves `P₁ ⟶ P₂` induces an isomorphism on the associated sheaves, then the induced map `P₁ ⋙ F ⟶ P₂ ⋙ F` also induces an isomorphism on the associated sheaves. (Note: it suffices to check this property for the map from any presheaf `P` to its associated sheaf, see `GrothendieckTopology.preservesSheafification_iff_of_adjunctions`). In general, we define `Sheaf.composeAndSheafify J F : Sheaf J A ⥤ Sheaf J B` as the functor which sends a sheaf `G` to the sheafification of the composition `G.val ⋙ F`. If `J.PreservesSheafification F`, we show that this functor can also be thought of as the localization of the functor `_ ⋙ F` on presheaves: we construct an isomorphism `presheafToSheafCompComposeAndSheafifyIso` between `presheafToSheaf J A ⋙ Sheaf.composeAndSheafify J F` and `(whiskeringRight Cᵒᵖ A B).obj F ⋙ presheafToSheaf J B`. Moreover, if we assume `J.HasSheafCompose F`, we obtain an isomorphism `sheafifyComposeIso J F P : sheafify J (P ⋙ F) ≅ sheafify J P ⋙ F`. We show that under suitable assumptions, the forgetful functor from a concrete category preserves sheafification; this holds more generally for functors between such concrete categories which commute both with suitable limits and colimits. ## TODO * construct an isomorphism `Sheaf.composeAndSheafify J F ≅ sheafCompose J F` -/ universe v u namespace CategoryTheory open Category Limits Functor variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) {A B : Type*} [Category A] [Category B] (F : A ⥤ B) namespace GrothendieckTopology /-- A functor `F : A ⥤ B` preserves the sheafification for the Grothendieck topology `J` on a category `C` if whenever a morphism of presheaves `f : P₁ ⟶ P₂` in `Cᵒᵖ ⥤ A` is such that becomes an iso after sheafification, then it is also the case of `whiskerRight f F : P₁ ⋙ F ⟶ P₂ ⋙ F`. -/ class PreservesSheafification : Prop where le : J.W ≤ J.W.inverseImage ((whiskeringRight Cᵒᵖ A B).obj F) variable [PreservesSheafification J F] lemma W_of_preservesSheafification {P₁ P₂ : Cᵒᵖ ⥤ A} (f : P₁ ⟶ P₂) (hf : J.W f) : J.W (whiskerRight f F) := PreservesSheafification.le _ hf variable [HasWeakSheafify J B] lemma W_isInvertedBy_whiskeringRight_presheafToSheaf : J.W.IsInvertedBy (((whiskeringRight Cᵒᵖ A B).obj F) ⋙ presheafToSheaf J B) := by intro P₁ P₂ f hf dsimp rw [← W_iff] exact J.W_of_preservesSheafification F _ hf end GrothendieckTopology section variable [HasWeakSheafify J B] /-- This is the functor sending a sheaf `X : Sheaf J A` to the sheafification of `X.val ⋙ F`. -/ noncomputable abbrev Sheaf.composeAndSheafify : Sheaf J A ⥤ Sheaf J B := sheafToPresheaf J A ⋙ (whiskeringRight _ _ _).obj F ⋙ presheafToSheaf J B variable [HasWeakSheafify J A] /-- The canonical natural transformation from `(whiskeringRight Cᵒᵖ A B).obj F ⋙ presheafToSheaf J B` to `presheafToSheaf J A ⋙ Sheaf.composeAndSheafify J F`. -/ @[simps!] noncomputable def toPresheafToSheafCompComposeAndSheafify : (whiskeringRight Cᵒᵖ A B).obj F ⋙ presheafToSheaf J B ⟶ presheafToSheaf J A ⋙ Sheaf.composeAndSheafify J F := whiskerRight (sheafificationAdjunction J A).unit ((whiskeringRight _ _ _).obj F ⋙ presheafToSheaf J B) variable [J.PreservesSheafification F] instance : IsIso (toPresheafToSheafCompComposeAndSheafify J F) := by rw [NatTrans.isIso_iff_isIso_app] intro X dsimp simpa only [← J.W_iff] using J.W_of_preservesSheafification F _ (J.W_toSheafify X) /-- The canonical isomorphism between `presheafToSheaf J A ⋙ Sheaf.composeAndSheafify J F` and `(whiskeringRight Cᵒᵖ A B).obj F ⋙ presheafToSheaf J B` when `F : A ⥤ B` preserves sheafification. -/ @[simps! inv_app] noncomputable def presheafToSheafCompComposeAndSheafifyIso : presheafToSheaf J A ⋙ Sheaf.composeAndSheafify J F ≅ (whiskeringRight Cᵒᵖ A B).obj F ⋙ presheafToSheaf J B := (asIso (toPresheafToSheafCompComposeAndSheafify J F)).symm noncomputable instance : Localization.Lifting (presheafToSheaf J A) J.W ((whiskeringRight Cᵒᵖ A B).obj F ⋙ presheafToSheaf J B) (Sheaf.composeAndSheafify J F) := ⟨presheafToSheafCompComposeAndSheafifyIso J F⟩ end section variable {G₁ : (Cᵒᵖ ⥤ A) ⥤ Sheaf J A} (adj₁ : G₁ ⊣ sheafToPresheaf J A) {G₂ : (Cᵒᵖ ⥤ B) ⥤ Sheaf J B} lemma GrothendieckTopology.preservesSheafification_iff_of_adjunctions (adj₂ : G₂ ⊣ sheafToPresheaf J B) : J.PreservesSheafification F ↔ ∀ (P : Cᵒᵖ ⥤ A), IsIso (G₂.map (whiskerRight (adj₁.unit.app P) F)) := by simp only [← J.W_iff_isIso_map_of_adjunction adj₂] constructor · intro _ P apply W_of_preservesSheafification rw [J.W_iff_isIso_map_of_adjunction adj₁] infer_instance · intro h constructor intro P₁ P₂ f hf rw [J.W_iff_isIso_map_of_adjunction adj₁] at hf dsimp [MorphismProperty.inverseImage] rw [← (W _).postcomp_iff _ _ (h P₂), ← whiskerRight_comp] erw [adj₁.unit.naturality f] dsimp only [Functor.comp_map] rw [whiskerRight_comp, (W _).precomp_iff _ _ (h P₁)] apply Localization.LeftBousfield.W_of_isIso section HasSheafCompose variable (adj₂ : G₂ ⊣ sheafToPresheaf J B) [J.HasSheafCompose F] /-- The canonical natural transformation `(whiskeringRight Cᵒᵖ A B).obj F ⋙ G₂ ⟶ G₁ ⋙ sheafCompose J F` when `F : A ⥤ B` is such that `J.HasSheafCompose F`, and that `G₁` and `G₂` are left adjoints to the forget functors `sheafToPresheaf`. -/ def sheafComposeNatTrans : (whiskeringRight Cᵒᵖ A B).obj F ⋙ G₂ ⟶ G₁ ⋙ sheafCompose J F where app P := (adj₂.homEquiv _ _).symm (whiskerRight (adj₁.unit.app P) F) naturality {P Q} f := by dsimp erw [← adj₂.homEquiv_naturality_left_symm, ← adj₂.homEquiv_naturality_right_symm] dsimp rw [← whiskerRight_comp, ← whiskerRight_comp] erw [adj₁.unit.naturality f] rfl lemma sheafComposeNatTrans_fac (P : Cᵒᵖ ⥤ A) : adj₂.unit.app (P ⋙ F) ≫ (sheafToPresheaf J B).map ((sheafComposeNatTrans J F adj₁ adj₂).app P) = whiskerRight (adj₁.unit.app P) F := by simp [sheafComposeNatTrans, -sheafToPresheaf_obj, -sheafToPresheaf_map, Adjunction.homEquiv_counit] lemma sheafComposeNatTrans_app_uniq (P : Cᵒᵖ ⥤ A) (α : G₂.obj (P ⋙ F) ⟶ (sheafCompose J F).obj (G₁.obj P)) (hα : adj₂.unit.app (P ⋙ F) ≫ (sheafToPresheaf J B).map α = whiskerRight (adj₁.unit.app P) F) : α = (sheafComposeNatTrans J F adj₁ adj₂).app P := by apply (adj₂.homEquiv _ _).injective dsimp [sheafComposeNatTrans] erw [Equiv.apply_symm_apply] rw [← hα] apply adj₂.homEquiv_unit lemma GrothendieckTopology.preservesSheafification_iff_of_adjunctions_of_hasSheafCompose : J.PreservesSheafification F ↔ IsIso (sheafComposeNatTrans J F adj₁ adj₂) := by rw [J.preservesSheafification_iff_of_adjunctions F adj₁ adj₂, NatTrans.isIso_iff_isIso_app] apply forall_congr' intro P rw [← J.W_iff_isIso_map_of_adjunction adj₂, ← J.W_sheafToPresheaf_map_iff_isIso, ← sheafComposeNatTrans_fac J F adj₁ adj₂, (W _).precomp_iff _ _ (J.W_adj_unit_app adj₂ (P ⋙ F))] variable [J.PreservesSheafification F] instance : IsIso (sheafComposeNatTrans J F adj₁ adj₂) := by rw [← J.preservesSheafification_iff_of_adjunctions_of_hasSheafCompose] infer_instance /-- The canonical natural isomorphism `(whiskeringRight Cᵒᵖ A B).obj F ⋙ G₂ ≅ G₁ ⋙ sheafCompose J F` when `F : A ⥤ B` preserves sheafification, and that `G₁` and `G₂` are left adjoints to the forget functors `sheafToPresheaf`. -/ noncomputable def sheafComposeNatIso : (whiskeringRight Cᵒᵖ A B).obj F ⋙ G₂ ≅ G₁ ⋙ sheafCompose J F := asIso (sheafComposeNatTrans J F adj₁ adj₂) end HasSheafCompose end section HasSheafCompose variable [HasWeakSheafify J A] [HasWeakSheafify J B] [J.HasSheafCompose F] [J.PreservesSheafification F] (P : Cᵒᵖ ⥤ A) /-- The canonical isomorphism `sheafify J (P ⋙ F) ≅ sheafify J P ⋙ F` when `F` preserves the sheafification. -/ noncomputable def sheafifyComposeIso : sheafify J (P ⋙ F) ≅ sheafify J P ⋙ F := (sheafToPresheaf J B).mapIso ((sheafComposeNatIso J F (sheafificationAdjunction J A) (sheafificationAdjunction J B)).app P) @[reassoc (attr := simp)] lemma sheafComposeIso_hom_fac : toSheafify J (P ⋙ F) ≫ (sheafifyComposeIso J F P).hom = whiskerRight (toSheafify J P) F := sheafComposeNatTrans_fac J F (sheafificationAdjunction J A) (sheafificationAdjunction J B) P @[reassoc (attr := simp)] lemma sheafComposeIso_inv_fac : whiskerRight (toSheafify J P) F ≫ (sheafifyComposeIso J F P).inv = toSheafify J (P ⋙ F) := by rw [← sheafComposeIso_hom_fac, assoc, Iso.hom_inv_id, comp_id] end HasSheafCompose namespace GrothendieckTopology section variable {D E : Type*} [Category.{max v u} D] [Category.{max v u} E] (F : D ⥤ E) [∀ (J : MulticospanShape.{max v u, max v u}), HasLimitsOfShape (WalkingMulticospan J) D] [∀ (J : MulticospanShape.{max v u, max v u}), HasLimitsOfShape (WalkingMulticospan J) E] [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ E] [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ F] [∀ (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F] {FD : D → D → Type*} {CD : D → Type (max v u)} {FE : E → E → Type*} {CE : E → Type (max v u)} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [∀ X Y, FunLike (FE X Y) (CE X) (CE Y)] [instCCD : ConcreteCategory D FD] [instCCE : ConcreteCategory E FE] [∀ X, PreservesColimitsOfShape (Cover J X)ᵒᵖ (forget D)] [∀ X, PreservesColimitsOfShape (Cover J X)ᵒᵖ (forget E)] [PreservesLimits (forget D)] [PreservesLimits (forget E)] [(forget D).ReflectsIsomorphisms] [(forget E).ReflectsIsomorphisms] include instCCD instCCE in lemma sheafToPresheaf_map_sheafComposeNatTrans_eq_sheafifyCompIso_inv (P : Cᵒᵖ ⥤ D) : (sheafToPresheaf J E).map ((sheafComposeNatTrans J F (plusPlusAdjunction J D) (plusPlusAdjunction J E)).app P) = (sheafifyCompIso J F P).inv := by suffices (sheafComposeNatTrans J F (plusPlusAdjunction J D) (plusPlusAdjunction J E)).app P = ⟨(sheafifyCompIso J F P).inv⟩ by rw [this] rfl apply ((plusPlusAdjunction J E).homEquiv _ _).injective convert sheafComposeNatTrans_fac J F (plusPlusAdjunction J D) (plusPlusAdjunction J E) P dsimp [plusPlusAdjunction] simp instance (P : Cᵒᵖ ⥤ D) : IsIso ((sheafComposeNatTrans J F (plusPlusAdjunction J D) (plusPlusAdjunction J E)).app P) := by rw [← isIso_iff_of_reflects_iso _ (sheafToPresheaf J E), sheafToPresheaf_map_sheafComposeNatTrans_eq_sheafifyCompIso_inv] infer_instance instance : IsIso (sheafComposeNatTrans J F (plusPlusAdjunction J D) (plusPlusAdjunction J E)) := NatIso.isIso_of_isIso_app _ instance : PreservesSheafification J F := by rw [preservesSheafification_iff_of_adjunctions_of_hasSheafCompose _ _ (plusPlusAdjunction J D) (plusPlusAdjunction J E)] infer_instance end attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance {D : Type*} [Category.{max v u} D] {FD : D → D → Type*} {CD : D → Type (max v u)} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{max v u} D FD] [PreservesLimits (forget D)] [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ (forget D)] [∀ (J : MulticospanShape.{max v u, max v u}), Limits.HasLimitsOfShape (Limits.WalkingMulticospan J) D] [(forget D).ReflectsIsomorphisms] : PreservesSheafification J (forget D) := inferInstance end GrothendieckTopology end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Sheaf.lean
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.Yoneda import Mathlib.CategoryTheory.Preadditive.FunctorCategory import Mathlib.CategoryTheory.Sites.SheafOfTypes import Mathlib.CategoryTheory.Sites.EqualizerSheafCondition import Mathlib.CategoryTheory.Limits.Constructions.EpiMono /-! # Sheaves taking values in a category If C is a category with a Grothendieck topology, we define the notion of a sheaf taking values in an arbitrary category `A`. We follow the definition in https://stacks.math.columbia.edu/tag/00VR, noting that the presheaf of sets "defined above" can be seen in the comments between tags 00VQ and 00VR on the page <https://stacks.math.columbia.edu/tag/00VL>. The advantage of this definition is that we need no assumptions whatsoever on `A` other than the assumption that the morphisms in `C` and `A` live in the same universe. * An `A`-valued presheaf `P : Cᵒᵖ ⥤ A` is defined to be a sheaf (for the topology `J`) iff for every `E : A`, the type-valued presheaves of sets given by sending `U : Cᵒᵖ` to `Hom_{A}(E, P U)` are all sheaves of sets, see `CategoryTheory.Presheaf.IsSheaf`. * When `A = Type`, this recovers the basic definition of sheaves of sets, see `CategoryTheory.isSheaf_iff_isSheaf_of_type`. * An alternate definition in terms of limits, unconditionally equivalent to the original one: see `CategoryTheory.Presheaf.isSheaf_iff_isLimit`. * An alternate definition when `C` is small, has pullbacks and `A` has products is given by an equalizer condition `CategoryTheory.Presheaf.IsSheaf'`. This is equivalent to the earlier definition, shown in `CategoryTheory.Presheaf.isSheaf_iff_isSheaf'`. * When `A = Type`, this is *definitionally* equal to the equalizer condition for presieves in `CategoryTheory.Sites.SheafOfTypes`. * When `A` has limits and there is a functor `s : A ⥤ Type` which is faithful, reflects isomorphisms and preserves limits, then `P : Cᵒᵖ ⥤ A` is a sheaf iff the underlying presheaf of types `P ⋙ s : Cᵒᵖ ⥤ Type` is a sheaf (`CategoryTheory.Presheaf.isSheaf_iff_isSheaf_forget`). Cf https://stacks.math.columbia.edu/tag/0073, which is a weaker version of this statement (it's only over spaces, not sites) and https://stacks.math.columbia.edu/tag/00YR (a), which additionally assumes filtered colimits. ## Implementation notes Occasionally we need to take a limit in `A` of a collection of morphisms of `C` indexed by a collection of objects in `C`. This turns out to force the morphisms of `A` to be in a sufficiently large universe. Rather than use `UnivLE` we prove some results for a category `A'` instead, whose morphism universe of `A'` is defined to be `max u₁ v₁`, where `u₁, v₁` are the universes for `C`. Perhaps after we get better at handling universe inequalities this can be changed. -/ universe w v₁ v₂ v₃ u₁ u₂ u₃ noncomputable section namespace CategoryTheory open Opposite CategoryTheory Category Limits Sieve namespace Presheaf variable {C : Type u₁} [Category.{v₁} C] variable {A : Type u₂} [Category.{v₂} A] variable (J : GrothendieckTopology C) -- We follow https://stacks.math.columbia.edu/tag/00VL definition 00VR /-- A sheaf of A is a presheaf `P : Cᵒᵖ ⥤ A` such that for every `E : A`, the presheaf of types given by sending `U : C` to `Hom_{A}(E, P U)` is a sheaf of types. -/ @[stacks 00VR] def IsSheaf (P : Cᵒᵖ ⥤ A) : Prop := ∀ E : A, Presieve.IsSheaf J (P ⋙ coyoneda.obj (op E)) /-- Condition that a presheaf with values in a concrete category is separated for a Grothendieck topology. -/ def IsSeparated (P : Cᵒᵖ ⥤ A) {FA : A → A → Type*} {CA : A → Type*} [∀ X Y, FunLike (FA X Y) (CA X) (CA Y)] [ConcreteCategory A FA] : Prop := ∀ (X : C) (S : Sieve X) (_ : S ∈ J X) (x y : ToType (P.obj (op X))), (∀ (Y : C) (f : Y ⟶ X) (_ : S f), P.map f.op x = P.map f.op y) → x = y section LimitSheafCondition open Presieve Presieve.FamilyOfElements Limits variable (P : Cᵒᵖ ⥤ A) {X : C} (S : Sieve X) (R : Presieve X) (E : Aᵒᵖ) /-- Given a sieve `S` on `X : C`, a presheaf `P : Cᵒᵖ ⥤ A`, and an object `E` of `A`, the cones over the natural diagram `S.arrows.diagram.op ⋙ P` associated to `S` and `P` with cone point `E` are in 1-1 correspondence with sieve_compatible family of elements for the sieve `S` and the presheaf of types `Hom (E, P -)`. -/ def conesEquivSieveCompatibleFamily : (S.arrows.diagram.op ⋙ P).cones.obj E ≃ { x : FamilyOfElements (P ⋙ coyoneda.obj E) (S : Presieve X) // x.SieveCompatible } where toFun π := ⟨fun _ f h => π.app (op ⟨Over.mk f, h⟩), fun X Y f g hf => by apply (id_comp _).symm.trans dsimp exact π.naturality (Quiver.Hom.op (Over.homMk _ (by rfl)))⟩ invFun x := { app := fun f => x.1 f.unop.1.hom f.unop.2 naturality := fun f f' g => by refine Eq.trans ?_ (x.2 f.unop.1.hom g.unop.left f.unop.2) dsimp rw [id_comp] convert rfl rw [Over.w] } variable {P S E} variable {x : FamilyOfElements (P ⋙ coyoneda.obj E) S.arrows} (hx : SieveCompatible x) /-- The cone corresponding to a sieve_compatible family of elements, dot notation enabled. -/ @[simp] def _root_.CategoryTheory.Presieve.FamilyOfElements.SieveCompatible.cone : Cone (S.arrows.diagram.op ⋙ P) where pt := E.unop π := (conesEquivSieveCompatibleFamily P S E).invFun ⟨x, hx⟩ /-- Cone morphisms from the cone corresponding to a sieve_compatible family to the natural cone associated to a sieve `S` and a presheaf `P` are in 1-1 correspondence with amalgamations of the family. -/ def homEquivAmalgamation : (hx.cone ⟶ P.mapCone S.arrows.cocone.op) ≃ { t // x.IsAmalgamation t } where toFun l := ⟨l.hom, fun _ f hf => l.w (op ⟨Over.mk f, hf⟩)⟩ invFun t := ⟨t.1, fun f => t.2 f.unop.1.hom f.unop.2⟩ variable (P S) /-- Given sieve `S` and presheaf `P : Cᵒᵖ ⥤ A`, their natural associated cone is a limit cone iff `Hom (E, P -)` is a sheaf of types for the sieve `S` and all `E : A`. -/ theorem isLimit_iff_isSheafFor : Nonempty (IsLimit (P.mapCone S.arrows.cocone.op)) ↔ ∀ E : Aᵒᵖ, IsSheafFor (P ⋙ coyoneda.obj E) S.arrows := by dsimp [IsSheafFor]; simp_rw [compatible_iff_sieveCompatible] rw [((Cone.isLimitEquivIsTerminal _).trans (isTerminalEquivUnique _ _)).nonempty_congr] rw [Classical.nonempty_pi]; constructor · intro hu E x hx specialize hu hx.cone rw [(homEquivAmalgamation hx).uniqueCongr.nonempty_congr] at hu exact (unique_subtype_iff_existsUnique _).1 hu · rintro h ⟨E, π⟩ let eqv := conesEquivSieveCompatibleFamily P S (op E) rw [← eqv.left_inv π] erw [(homEquivAmalgamation (eqv π).2).uniqueCongr.nonempty_congr] rw [unique_subtype_iff_existsUnique] exact h _ _ (eqv π).2 /-- Given sieve `S` and presheaf `P : Cᵒᵖ ⥤ A`, their natural associated cone admits at most one morphism from every cone in the same category (i.e. over the same diagram), iff `Hom (E, P -)`is separated for the sieve `S` and all `E : A`. -/ theorem subsingleton_iff_isSeparatedFor : (∀ c, Subsingleton (c ⟶ P.mapCone S.arrows.cocone.op)) ↔ ∀ E : Aᵒᵖ, IsSeparatedFor (P ⋙ coyoneda.obj E) S.arrows := by constructor · intro hs E x t₁ t₂ h₁ h₂ have hx := is_compatible_of_exists_amalgamation x ⟨t₁, h₁⟩ rw [compatible_iff_sieveCompatible] at hx specialize hs hx.cone rcases hs with ⟨hs⟩ simpa only [Subtype.mk.injEq] using (show Subtype.mk t₁ h₁ = ⟨t₂, h₂⟩ from (homEquivAmalgamation hx).symm.injective (hs _ _)) · rintro h ⟨E, π⟩ let eqv := conesEquivSieveCompatibleFamily P S (op E) constructor rw [← eqv.left_inv π] intro f₁ f₂ let eqv' := homEquivAmalgamation (eqv π).2 apply eqv'.injective ext apply h _ (eqv π).1 <;> exact (eqv' _).2 /-- A presheaf `P` is a sheaf for the Grothendieck topology `J` iff for every covering sieve `S` of `J`, the natural cone associated to `P` and `S` is a limit cone. -/ theorem isSheaf_iff_isLimit : IsSheaf J P ↔ ∀ ⦃X : C⦄ (S : Sieve X), S ∈ J X → Nonempty (IsLimit (P.mapCone S.arrows.cocone.op)) := ⟨fun h _ S hS => (isLimit_iff_isSheafFor P S).2 fun E => h E.unop S hS, fun h E _ S hS => (isLimit_iff_isSheafFor P S).1 (h S hS) (op E)⟩ /-- A presheaf `P` is separated for the Grothendieck topology `J` iff for every covering sieve `S` of `J`, the natural cone associated to `P` and `S` admits at most one morphism from every cone in the same category. -/ theorem isSeparated_iff_subsingleton : (∀ E : A, Presieve.IsSeparated J (P ⋙ coyoneda.obj (op E))) ↔ ∀ ⦃X : C⦄ (S : Sieve X), S ∈ J X → ∀ c, Subsingleton (c ⟶ P.mapCone S.arrows.cocone.op) := ⟨fun h _ S hS => (subsingleton_iff_isSeparatedFor P S).2 fun E => h E.unop S hS, fun h E _ S hS => (subsingleton_iff_isSeparatedFor P S).1 (h S hS) (op E)⟩ /-- Given presieve `R` and presheaf `P : Cᵒᵖ ⥤ A`, the natural cone associated to `P` and the sieve `Sieve.generate R` generated by `R` is a limit cone iff `Hom (E, P -)` is a sheaf of types for the presieve `R` and all `E : A`. -/ theorem isLimit_iff_isSheafFor_presieve : Nonempty (IsLimit (P.mapCone (generate R).arrows.cocone.op)) ↔ ∀ E : Aᵒᵖ, IsSheafFor (P ⋙ coyoneda.obj E) R := (isLimit_iff_isSheafFor P _).trans (forall_congr' fun _ => (isSheafFor_iff_generate _).symm) /-- A presheaf `P` is a sheaf for the Grothendieck topology generated by a pretopology `K` iff for every covering presieve `R` of `K`, the natural cone associated to `P` and `Sieve.generate R` is a limit cone. -/ theorem isSheaf_iff_isLimit_pretopology [HasPullbacks C] (K : Pretopology C) : IsSheaf K.toGrothendieck P ↔ ∀ ⦃X : C⦄ (R : Presieve X), R ∈ K X → Nonempty (IsLimit (P.mapCone (generate R).arrows.cocone.op)) := by dsimp [IsSheaf] simp_rw [isSheaf_pretopology] exact ⟨fun h X R hR => (isLimit_iff_isSheafFor_presieve P R).2 fun E => h E.unop R hR, fun h E X R hR => (isLimit_iff_isSheafFor_presieve P R).1 (h R hR) (op E)⟩ end LimitSheafCondition variable {J} /-- This is a wrapper around `Presieve.IsSheafFor.amalgamate` to be used below. If `P` is a sheaf, `S` is a cover of `X`, and `x` is a collection of morphisms from `E` to `P` evaluated at terms in the cover which are compatible, then we can amalgamate the `x`s to obtain a single morphism `E ⟶ P.obj (op X)`. -/ def IsSheaf.amalgamate {A : Type u₂} [Category.{v₂} A] {E : A} {X : C} {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) (S : J.Cover X) (x : ∀ I : S.Arrow, E ⟶ P.obj (op I.Y)) (hx : ∀ ⦃I₁ I₂ : S.Arrow⦄ (r : I₁.Relation I₂), x I₁ ≫ P.map r.g₁.op = x I₂ ≫ P.map r.g₂.op) : E ⟶ P.obj (op X) := (hP _ _ S.condition).amalgamate (fun Y f hf => x ⟨Y, f, hf⟩) fun _ _ _ _ _ _ _ h₁ h₂ w => @hx { hf := h₁, .. } { hf := h₂, .. } { w := w, .. } @[reassoc (attr := simp)] theorem IsSheaf.amalgamate_map {A : Type u₂} [Category.{v₂} A] {E : A} {X : C} {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) (S : J.Cover X) (x : ∀ I : S.Arrow, E ⟶ P.obj (op I.Y)) (hx : ∀ ⦃I₁ I₂ : S.Arrow⦄ (r : I₁.Relation I₂), x I₁ ≫ P.map r.g₁.op = x I₂ ≫ P.map r.g₂.op) (I : S.Arrow) : hP.amalgamate S x hx ≫ P.map I.f.op = x _ := by apply (hP _ _ S.condition).valid_glue theorem IsSheaf.hom_ext {A : Type u₂} [Category.{v₂} A] {E : A} {X : C} {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) (S : J.Cover X) (e₁ e₂ : E ⟶ P.obj (op X)) (h : ∀ I : S.Arrow, e₁ ≫ P.map I.f.op = e₂ ≫ P.map I.f.op) : e₁ = e₂ := (hP _ _ S.condition).isSeparatedFor.ext fun Y f hf => h ⟨Y, f, hf⟩ lemma IsSheaf.hom_ext_ofArrows {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) {I : Type*} {S : C} {X : I → C} (f : ∀ i, X i ⟶ S) (hf : Sieve.ofArrows _ f ∈ J S) {E : A} {x y : E ⟶ P.obj (op S)} (h : ∀ i, x ≫ P.map (f i).op = y ≫ P.map (f i).op) : x = y := by apply hP.hom_ext ⟨_, hf⟩ rintro ⟨Z, _, _, g, _, ⟨i⟩, rfl⟩ dsimp rw [P.map_comp, reassoc_of% (h i)] section variable {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) {I : Type*} {S : C} {X : I → C} (f : ∀ i, X i ⟶ S) (hf : Sieve.ofArrows _ f ∈ J S) {E : A} (x : ∀ i, E ⟶ P.obj (op (X i))) (hx : ∀ ⦃W : C⦄ ⦃i j : I⦄ (a : W ⟶ X i) (b : W ⟶ X j), a ≫ f i = b ≫ f j → x i ≫ P.map a.op = x j ≫ P.map b.op) include hP hf hx lemma IsSheaf.existsUnique_amalgamation_ofArrows : ∃! (g : E ⟶ P.obj (op S)), ∀ (i : I), g ≫ P.map (f i).op = x i := (Presieve.isSheafFor_arrows_iff _ _).1 ((Presieve.isSheafFor_iff_generate _).2 (hP E _ hf)) x (fun _ _ _ _ _ w => hx _ _ w) /-- If `P : Cᵒᵖ ⥤ A` is a sheaf and `f i : X i ⟶ S` is a covering family, then a morphism `E ⟶ P.obj (op S)` can be constructed from a compatible family of morphisms `x : E ⟶ P.obj (op (X i))`. -/ def IsSheaf.amalgamateOfArrows : E ⟶ P.obj (op S) := (hP.existsUnique_amalgamation_ofArrows f hf x hx).choose @[reassoc (attr := simp)] lemma IsSheaf.amalgamateOfArrows_map (i : I) : hP.amalgamateOfArrows f hf x hx ≫ P.map (f i).op = x i := (hP.existsUnique_amalgamation_ofArrows f hf x hx).choose_spec.1 i end theorem isSheaf_of_iso_iff {P P' : Cᵒᵖ ⥤ A} (e : P ≅ P') : IsSheaf J P ↔ IsSheaf J P' := forall_congr' fun _ => ⟨Presieve.isSheaf_iso J (Functor.isoWhiskerRight e _), Presieve.isSheaf_iso J (Functor.isoWhiskerRight e.symm _)⟩ variable (J) theorem isSheaf_of_isTerminal {X : A} (hX : IsTerminal X) : Presheaf.IsSheaf J ((CategoryTheory.Functor.const _).obj X) := fun _ _ _ _ _ _ => ⟨hX.from _, fun _ _ _ => hX.hom_ext _ _, fun _ _ => hX.hom_ext _ _⟩ end Presheaf variable {C : Type u₁} [Category.{v₁} C] variable (J : GrothendieckTopology C) variable (A : Type u₂) [Category.{v₂} A] /-- The category of sheaves taking values in `A` on a Grothendieck topology. -/ structure Sheaf where /-- the underlying presheaf -/ val : Cᵒᵖ ⥤ A /-- the condition that the presheaf is a sheaf -/ cond : Presheaf.IsSheaf J val namespace Sheaf variable {J A} /-- Morphisms between sheaves are just morphisms of presheaves. -/ @[ext] structure Hom (X Y : Sheaf J A) where /-- a morphism between the underlying presheaves -/ val : X.val ⟶ Y.val @[simps id_val comp_val] instance instCategorySheaf : Category (Sheaf J A) where Hom := Hom id _ := ⟨𝟙 _⟩ comp f g := ⟨f.val ≫ g.val⟩ id_comp _ := Hom.ext <| id_comp _ comp_id _ := Hom.ext <| comp_id _ assoc _ _ _ := Hom.ext <| assoc _ _ _ -- Let's make the inhabited linter happy.../sips instance (X : Sheaf J A) : Inhabited (Hom X X) := ⟨𝟙 X⟩ @[ext] lemma hom_ext {X Y : Sheaf J A} (x y : X ⟶ Y) (h : x.val = y.val) : x = y := Sheaf.Hom.ext h end Sheaf /-- The inclusion functor from sheaves to presheaves. -/ @[simps] def sheafToPresheaf : Sheaf J A ⥤ Cᵒᵖ ⥤ A where obj := Sheaf.val map f := f.val map_id _ := rfl map_comp _ _ := rfl /-- The sections of a sheaf (i.e. evaluation as a presheaf on `C`). -/ abbrev sheafSections : Cᵒᵖ ⥤ Sheaf J A ⥤ A := (sheafToPresheaf J A).flip /-- The sheaf sections functor on `X` is given by evaluation of presheaves on `X`. -/ @[simps!] def sheafSectionsNatIsoEvaluation {X : C} : (sheafSections J A).obj (op X) ≅ sheafToPresheaf J A ⋙ (evaluation _ _).obj (op X) := NatIso.ofComponents (fun _ ↦ Iso.refl _) /-- The functor `Sheaf J A ⥤ Cᵒᵖ ⥤ A` is fully faithful. -/ @[simps] def fullyFaithfulSheafToPresheaf : (sheafToPresheaf J A).FullyFaithful where preimage f := ⟨f⟩ variable {J A} in /-- The bijection `(X ⟶ Y) ≃ (X.val ⟶ Y.val)` when `X` and `Y` are sheaves. -/ abbrev Sheaf.homEquiv {X Y : Sheaf J A} : (X ⟶ Y) ≃ (X.val ⟶ Y.val) := (fullyFaithfulSheafToPresheaf J A).homEquiv instance : (sheafToPresheaf J A).Full := (fullyFaithfulSheafToPresheaf J A).full instance : (sheafToPresheaf J A).Faithful := (fullyFaithfulSheafToPresheaf J A).faithful instance : (sheafToPresheaf J A).ReflectsIsomorphisms := (fullyFaithfulSheafToPresheaf J A).reflectsIsomorphisms /-- This is stated as a lemma to prevent class search from forming a loop since a sheaf morphism is monic if and only if it is monic as a presheaf morphism (under suitable assumption). -/ theorem Sheaf.Hom.mono_of_presheaf_mono {F G : Sheaf J A} (f : F ⟶ G) [h : Mono f.1] : Mono f := (sheafToPresheaf J A).mono_of_mono_map h instance Sheaf.Hom.epi_of_presheaf_epi {F G : Sheaf J A} (f : F ⟶ G) [h : Epi f.1] : Epi f := (sheafToPresheaf J A).epi_of_epi_map h theorem isSheaf_iff_isSheaf_of_type (P : Cᵒᵖ ⥤ Type w) : Presheaf.IsSheaf J P ↔ Presieve.IsSheaf J P := by constructor · intro hP refine Presieve.isSheaf_iso J ?_ (hP PUnit) exact Functor.isoWhiskerLeft _ Coyoneda.punitIso ≪≫ P.rightUnitor · intro hP X Y S hS z hz refine ⟨fun x => (hP S hS).amalgamate (fun Z f hf => z f hf x) ?_, ?_, ?_⟩ · intro Y₁ Y₂ Z g₁ g₂ f₁ f₂ hf₁ hf₂ h exact congr_fun (hz g₁ g₂ hf₁ hf₂ h) x · intro Z f hf funext x apply Presieve.IsSheafFor.valid_glue · intro y hy funext x apply (hP S hS).isSeparatedFor.ext intro Y' f hf rw [Presieve.IsSheafFor.valid_glue _ _ _ hf, ← hy _ hf] rfl /-- The sheaf of sections guaranteed by the sheaf condition. -/ @[simps] def sheafOver {A : Type u₂} [Category.{v₂} A] {J : GrothendieckTopology C} (ℱ : Sheaf J A) (E : A) : Sheaf J (Type _) where val := ℱ.val ⋙ coyoneda.obj (op E) cond := by rw [isSheaf_iff_isSheaf_of_type] exact ℱ.cond E variable {J} in lemma Presheaf.IsSheaf.isSheafFor {P : Cᵒᵖ ⥤ Type w} (hP : Presheaf.IsSheaf J P) {X : C} (S : Sieve X) (hS : S ∈ J X) : Presieve.IsSheafFor P S.arrows := by rw [isSheaf_iff_isSheaf_of_type] at hP exact hP S hS variable {A} in lemma Presheaf.isSheaf_bot (P : Cᵒᵖ ⥤ A) : IsSheaf ⊥ P := fun _ ↦ Presieve.isSheaf_bot /-- The category of sheaves on the bottom (trivial) Grothendieck topology is equivalent to the category of presheaves. -/ @[simps] def sheafBotEquivalence : Sheaf (⊥ : GrothendieckTopology C) A ≌ Cᵒᵖ ⥤ A where functor := sheafToPresheaf _ _ inverse := { obj := fun P => ⟨P, Presheaf.isSheaf_bot P⟩ map := fun f => ⟨f⟩ } unitIso := Iso.refl _ counitIso := Iso.refl _ instance : Inhabited (Sheaf (⊥ : GrothendieckTopology C) (Type w)) := ⟨(sheafBotEquivalence _).inverse.obj ((Functor.const _).obj default)⟩ variable {J} {A} /-- If the empty sieve is a cover of `X`, then `F(X)` is terminal. -/ def Sheaf.isTerminalOfBotCover (F : Sheaf J A) (X : C) (H : ⊥ ∈ J X) : IsTerminal (F.1.obj (op X)) := by refine @IsTerminal.ofUnique _ _ _ ?_ intro Y choose t h using F.2 Y _ H (by tauto) (by tauto) exact ⟨⟨t⟩, fun a => h.2 a (by tauto)⟩ section Preadditive open Preadditive variable [Preadditive A] {P Q : Sheaf J A} instance sheafHomHasZSMul : SMul ℤ (P ⟶ Q) where smul n f := Sheaf.Hom.mk { app := fun U => n • f.1.app U naturality := fun U V i => by induction n with | zero => simp only [zero_smul, comp_zero, zero_comp] | succ n ih => simpa only [add_zsmul, one_zsmul, comp_add, NatTrans.naturality, add_comp, add_left_inj] | pred n ih => simpa only [sub_smul, one_zsmul, comp_sub, NatTrans.naturality, sub_comp, sub_left_inj] using ih } instance : Sub (P ⟶ Q) where sub f g := Sheaf.Hom.mk <| f.1 - g.1 instance : Neg (P ⟶ Q) where neg f := Sheaf.Hom.mk <| -f.1 instance sheafHomHasNSMul : SMul ℕ (P ⟶ Q) where smul n f := Sheaf.Hom.mk { app := fun U => n • f.1.app U naturality := fun U V i => by induction n with | zero => simp only [zero_smul, comp_zero, zero_comp] | succ n ih => simp only [add_smul, ih, one_nsmul, comp_add, NatTrans.naturality, add_comp] } instance : Zero (P ⟶ Q) where zero := Sheaf.Hom.mk 0 instance : Add (P ⟶ Q) where add f g := Sheaf.Hom.mk <| f.1 + g.1 @[simp] theorem Sheaf.Hom.add_app (f g : P ⟶ Q) (U) : (f + g).1.app U = f.1.app U + g.1.app U := rfl instance Sheaf.Hom.addCommGroup : AddCommGroup (P ⟶ Q) := Function.Injective.addCommGroup (fun f : Sheaf.Hom P Q => f.1) (fun _ _ h => Sheaf.Hom.ext h) rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => by cat_disch) (fun _ _ => by cat_disch) instance : Preadditive (Sheaf J A) where homGroup _ _ := Sheaf.Hom.addCommGroup end Preadditive end CategoryTheory namespace CategoryTheory open Opposite CategoryTheory Category Limits Sieve namespace Presheaf -- Under here is the equalizer story, which is equivalent if A has products (and doesn't -- make sense otherwise). It's described in https://stacks.math.columbia.edu/tag/00VL, -- between 00VQ and 00VR. variable {C : Type u₁} [Category.{v₁} C] -- `A` is a general category; `A'` is a variant where the morphisms live in a large enough -- universe to guarantee that we can take limits in A of things coming from C. -- I would have liked to use something like `UnivLE.{max v₁ u₁, v₂}` as a hypothesis on -- `A`'s morphism universe rather than introducing `A'` but I can't get it to work. -- So, for now, results which need max v₁ u₁ ≤ v₂ are just stated for `A'` and `P' : Cᵒᵖ ⥤ A'` -- instead. variable {A : Type u₂} [Category.{v₂} A] variable {A' : Type u₂} [Category.{max v₁ u₁} A'] variable {B : Type u₃} [Category.{v₃} B] variable (J : GrothendieckTopology C) variable {U : C} (R : Presieve U) variable (P : Cᵒᵖ ⥤ A) (P' : Cᵒᵖ ⥤ A') section MultiequalizerConditions /-- When `P` is a sheaf and `S` is a cover, the associated multifork is a limit. -/ def isLimitOfIsSheaf {X : C} (S : J.Cover X) (hP : IsSheaf J P) : IsLimit (S.multifork P) where lift := fun E : Multifork _ => hP.amalgamate S (fun _ => E.ι _) (fun _ _ r => E.condition ⟨r⟩) fac := by rintro (E : Multifork _) (a | b) · apply hP.amalgamate_map · rw [← E.w (WalkingMulticospan.Hom.fst b), ← (S.multifork P).w (WalkingMulticospan.Hom.fst b), ← assoc] congr 1 apply hP.amalgamate_map uniq := by rintro (E : Multifork _) m hm apply hP.hom_ext S intro I erw [hm (WalkingMulticospan.left I)] symm apply hP.amalgamate_map theorem isSheaf_iff_multifork : IsSheaf J P ↔ ∀ (X : C) (S : J.Cover X), Nonempty (IsLimit (S.multifork P)) := by refine ⟨fun hP X S => ⟨isLimitOfIsSheaf _ _ _ hP⟩, ?_⟩ intro h E X S hS x hx let T : J.Cover X := ⟨S, hS⟩ obtain ⟨hh⟩ := h _ T let K : Multifork (T.index P) := Multifork.ofι _ E (fun I => x I.f I.hf) (fun I => hx _ _ _ _ I.r.w) use hh.lift K dsimp; constructor · intro Y f hf apply hh.fac K (WalkingMulticospan.left ⟨Y, f, hf⟩) · intro e he apply hh.uniq K rintro (a | b) · apply he · rw [← K.w (WalkingMulticospan.Hom.fst b), ← (T.multifork P).w (WalkingMulticospan.Hom.fst b), ← assoc] congr 1 apply he variable {J P} in /-- If `F : Cᵒᵖ ⥤ A` is a sheaf for a Grothendieck topology `J` on `C`, and `S` is a cover of `X : C`, then the multifork `S.multifork F` is limit. -/ def IsSheaf.isLimitMultifork (hP : Presheaf.IsSheaf J P) {X : C} (S : J.Cover X) : IsLimit (S.multifork P) := by rw [Presheaf.isSheaf_iff_multifork] at hP exact (hP X S).some theorem isSheaf_iff_multiequalizer [∀ (X : C) (S : J.Cover X), HasMultiequalizer (S.index P)] : IsSheaf J P ↔ ∀ (X : C) (S : J.Cover X), IsIso (S.toMultiequalizer P) := by rw [isSheaf_iff_multifork] refine forall₂_congr fun X S => ⟨?_, ?_⟩ · rintro ⟨h⟩ let e : P.obj (op X) ≅ multiequalizer (S.index P) := h.conePointUniqueUpToIso (limit.isLimit _) exact (inferInstance : IsIso e.hom) · intro h refine ⟨IsLimit.ofIsoLimit (limit.isLimit _) (Cones.ext ?_ ?_)⟩ · apply (@asIso _ _ _ _ _ h).symm · intro a symm simp end MultiequalizerConditions section variable [HasProducts.{max u₁ v₁} A] variable [HasProducts.{max u₁ v₁} A'] /-- The middle object of the fork diagram given in Equation (3) of [MM92], as well as the fork diagram of the Stacks entry. -/ @[stacks 00VM "The middle object of the fork diagram there."] def firstObj : A := ∏ᶜ fun f : Σ V, { f : V ⟶ U // R f } => P.obj (op f.1) /-- The left morphism of the fork diagram given in Equation (3) of [MM92], as well as the fork diagram of the Stacks entry. -/ @[stacks 00VM "The left morphism the fork diagram there."] def forkMap : P.obj (op U) ⟶ firstObj R P := Pi.lift fun f => P.map f.2.1.op variable [HasPullbacks C] /-- The rightmost object of the fork diagram of the Stacks entry, which contains the data used to check a family of elements for a presieve is compatible. -/ @[stacks 00VM "The rightmost object of the fork diagram there."] def secondObj : A := ∏ᶜ fun fg : (Σ V, { f : V ⟶ U // R f }) × Σ W, { g : W ⟶ U // R g } => P.obj (op (pullback fg.1.2.1 fg.2.2.1)) /-- The map `pr₀*` of the Stacks entry. -/ @[stacks 00VM "The map `pr₀*` there."] def firstMap : firstObj R P ⟶ secondObj R P := Pi.lift fun _ => Pi.π _ _ ≫ P.map (pullback.fst _ _).op /-- The map `pr₁*` of the Stacks entry. -/ @[stacks 00VM "The map `pr₁*` there."] def secondMap : firstObj R P ⟶ secondObj R P := Pi.lift fun _ => Pi.π _ _ ≫ P.map (pullback.snd _ _).op theorem w : forkMap R P ≫ firstMap R P = forkMap R P ≫ secondMap R P := by apply limit.hom_ext rintro ⟨⟨Y, f, hf⟩, ⟨Z, g, hg⟩⟩ simp only [firstMap, secondMap, forkMap, limit.lift_π, limit.lift_π_assoc, assoc, Fan.mk_π_app, Subtype.coe_mk] rw [← P.map_comp, ← op_comp, pullback.condition] simp /-- An alternative definition of the sheaf condition in terms of equalizers. This is shown to be equivalent in `CategoryTheory.Presheaf.isSheaf_iff_isSheaf'`. -/ def IsSheaf' (P : Cᵒᵖ ⥤ A) : Prop := ∀ (U : C) (R : Presieve U) (_ : generate R ∈ J U), Nonempty (IsLimit (Fork.ofι _ (w R P))) -- Again I wonder whether `UnivLE` can somehow be used to allow `s` to take -- values in a more general universe. /-- (Implementation). An auxiliary lemma to convert between sheaf conditions. -/ def isSheafForIsSheafFor' (P : Cᵒᵖ ⥤ A) (s : A ⥤ Type max v₁ u₁) [∀ J, PreservesLimitsOfShape (Discrete.{max v₁ u₁} J) s] (U : C) (R : Presieve U) : IsLimit (s.mapCone (Fork.ofι _ (w R P))) ≃ IsLimit (Fork.ofι _ (Equalizer.Presieve.w (P ⋙ s) R)) := by let e : parallelPair (s.map (firstMap R P)) (s.map (secondMap R P)) ≅ parallelPair (Equalizer.Presieve.firstMap (P ⋙ s) R) (Equalizer.Presieve.secondMap (P ⋙ s) R) := by refine parallelPair.ext (PreservesProduct.iso s _) ((PreservesProduct.iso s _)) (limit.hom_ext (fun j => ?_)) (limit.hom_ext (fun j => ?_)) · dsimp [Equalizer.Presieve.firstMap, firstMap] simp only [map_lift_piComparison, Functor.map_comp, limit.lift_π, Fan.mk_pt, Fan.mk_π_app, assoc, piComparison_comp_π_assoc] · dsimp [Equalizer.Presieve.secondMap, secondMap] simp only [map_lift_piComparison, Functor.map_comp, limit.lift_π, Fan.mk_pt, Fan.mk_π_app, assoc, piComparison_comp_π_assoc] refine Equiv.trans (isLimitMapConeForkEquiv _ _) ?_ refine (IsLimit.postcomposeHomEquiv e _).symm.trans (IsLimit.equivIsoLimit (Fork.ext (Iso.refl _) ?_)) dsimp [Equalizer.forkMap, forkMap, e, Fork.ι] simp only [id_comp, map_lift_piComparison] -- Remark : this lemma uses `A'` not `A`; `A'` is `A` but with a universe -- restriction. Can it be generalised? /-- The equalizer definition of a sheaf given by `isSheaf'` is equivalent to `isSheaf`. -/ theorem isSheaf_iff_isSheaf' : IsSheaf J P' ↔ IsSheaf' J P' := by constructor · intro h U R hR refine ⟨?_⟩ apply coyonedaJointlyReflectsLimits intro X have q : Presieve.IsSheafFor (P' ⋙ coyoneda.obj X) _ := h X.unop _ hR rw [← Presieve.isSheafFor_iff_generate] at q rw [Equalizer.Presieve.sheaf_condition] at q replace q := Classical.choice q apply (isSheafForIsSheafFor' _ _ _ _).symm q · intro h U X S hS rw [Equalizer.Presieve.sheaf_condition] refine ⟨?_⟩ refine isSheafForIsSheafFor' _ _ _ _ ?_ letI := preservesSmallestLimits_of_preservesLimits (coyoneda.obj (op U)) apply isLimitOfPreserves apply Classical.choice (h _ S.arrows _) simpa end section Concrete theorem isSheaf_of_isSheaf_comp (s : A ⥤ B) [ReflectsLimitsOfSize.{v₁, max v₁ u₁} s] (h : IsSheaf J (P ⋙ s)) : IsSheaf J P := by rw [isSheaf_iff_isLimit] at h ⊢ exact fun X S hS ↦ (h S hS).map fun t ↦ isLimitOfReflects s t theorem isSheaf_comp_of_isSheaf (s : A ⥤ B) [PreservesLimitsOfSize.{v₁, max v₁ u₁} s] (h : IsSheaf J P) : IsSheaf J (P ⋙ s) := by rw [isSheaf_iff_isLimit] at h ⊢ apply fun X S hS ↦ (h S hS).map fun t ↦ isLimitOfPreserves s t theorem isSheaf_iff_isSheaf_comp (s : A ⥤ B) [HasLimitsOfSize.{v₁, max v₁ u₁} A] [PreservesLimitsOfSize.{v₁, max v₁ u₁} s] [s.ReflectsIsomorphisms] : IsSheaf J P ↔ IsSheaf J (P ⋙ s) := by letI : ReflectsLimitsOfSize s := reflectsLimits_of_reflectsIsomorphisms exact ⟨isSheaf_comp_of_isSheaf J P s, isSheaf_of_isSheaf_comp J P s⟩ /-- For a concrete category `(A, s)` where the forgetful functor `s : A ⥤ Type v` preserves limits and reflects isomorphisms, and `A` has limits, an `A`-valued presheaf `P : Cᵒᵖ ⥤ A` is a sheaf iff its underlying `Type`-valued presheaf `P ⋙ s : Cᵒᵖ ⥤ Type` is a sheaf. Note this lemma applies for "algebraic" categories, e.g. groups, abelian groups and rings, but not for the category of topological spaces, topological rings, etc. since reflecting isomorphisms does not hold. -/ theorem isSheaf_iff_isSheaf_forget (s : A' ⥤ Type max v₁ u₁) [HasLimits A'] [PreservesLimits s] [s.ReflectsIsomorphisms] : IsSheaf J P' ↔ IsSheaf J (P' ⋙ s) := by have : HasLimitsOfSize.{v₁, max v₁ u₁} A' := hasLimitsOfSizeShrink.{_, _, u₁, 0} A' have : PreservesLimitsOfSize.{v₁, max v₁ u₁} s := preservesLimitsOfSize_shrink.{_, 0, _, u₁} s apply isSheaf_iff_isSheaf_comp end Concrete end Presheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Grothendieck.lean
import Mathlib.CategoryTheory.Sites.Sieves import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.Category.Preorder import Mathlib.Order.Copy import Mathlib.Data.Set.Subsingleton /-! # Grothendieck topologies Definition and lemmas about Grothendieck topologies. A Grothendieck topology for a category `C` is a set of sieves on each object `X` satisfying certain closure conditions. Alternate versions of the axioms (in arrow form) are also described. Two explicit examples of Grothendieck topologies are given: * The dense topology * The atomic topology as well as the complete lattice structure on Grothendieck topologies (which gives two additional explicit topologies: the discrete and trivial topologies.) A pretopology, or a basis for a topology is defined in `Mathlib/CategoryTheory/Sites/Pretopology.lean`. The topology associated to a topological space is defined in `Mathlib/CategoryTheory/Sites/Spaces.lean`. ## Tags Grothendieck topology, coverage, pretopology, site ## References * [nLab, *Grothendieck topology*](https://ncatlab.org/nlab/show/Grothendieck+topology) * [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92] ## Implementation notes We use the definition of [nlab] and [MM92][] (Chapter III, Section 2), where Grothendieck topologies are saturated collections of morphisms, rather than the notions of the Stacks project (00VG) and the Elephant, in which topologies are allowed to be unsaturated, and are then completed. TODO (BM): Add the definition from Stacks, as a pretopology, and complete to a topology. This is so that we can produce a bijective correspondence between Grothendieck topologies on a small category and Lawvere-Tierney topologies on its presheaf topos, as well as the equivalence between Grothendieck topoi and left exact reflective subcategories of presheaf toposes. -/ universe v₁ u₁ v u namespace CategoryTheory open Category variable (C : Type u) [Category.{v} C] /-- The definition of a Grothendieck topology: a set of sieves `J X` on each object `X` satisfying three axioms: 1. For every object `X`, the maximal sieve is in `J X`. 2. If `S ∈ J X` then its pullback along any `h : Y ⟶ X` is in `J Y`. 3. If `S ∈ J X` and `R` is a sieve on `X`, then provided that the pullback of `R` along any arrow `f : Y ⟶ X` in `S` is in `J Y`, we have that `R` itself is in `J X`. A sieve `S` on `X` is referred to as `J`-covering, (or just covering), if `S ∈ J X`. See also [nlab] or [MM92] Chapter III, Section 2, Definition 1. -/ @[stacks 00Z4] structure GrothendieckTopology where /-- A Grothendieck topology on `C` consists of a set of sieves for each object `X`, which satisfy some axioms. -/ sieves : ∀ X : C, Set (Sieve X) /-- The sieves associated to each object must contain the top sieve. Use `GrothendieckTopology.top_mem`. -/ top_mem' : ∀ X, ⊤ ∈ sieves X /-- Stability under pullback. Use `GrothendieckTopology.pullback_stable`. -/ pullback_stable' : ∀ ⦃X Y : C⦄ ⦃S : Sieve X⦄ (f : Y ⟶ X), S ∈ sieves X → S.pullback f ∈ sieves Y /-- Transitivity of sieves in a Grothendieck topology. Use `GrothendieckTopology.transitive`. -/ transitive' : ∀ ⦃X⦄ ⦃S : Sieve X⦄ (_ : S ∈ sieves X) (R : Sieve X), (∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → R.pullback f ∈ sieves Y) → R ∈ sieves X namespace GrothendieckTopology instance : DFunLike (GrothendieckTopology C) C (fun X ↦ Set (Sieve X)) where coe J X := sieves J X coe_injective' J₁ J₂ h := by cases J₁; cases J₂; congr variable {C} variable {X Y : C} {S R : Sieve X} variable (J : GrothendieckTopology C) /-- An extensionality lemma in terms of the coercion to a pi-type. We prove this explicitly rather than deriving it so that it is in terms of the coercion rather than the projection `.sieves`. -/ @[ext] theorem ext {J₁ J₂ : GrothendieckTopology C} (h : (J₁ : ∀ X : C, Set (Sieve X)) = J₂) : J₁ = J₂ := DFunLike.coe_injective h @[simp] theorem mem_sieves_iff_coe : S ∈ J.sieves X ↔ S ∈ J X := Iff.rfl /-- Also known as the maximality axiom. -/ @[simp] theorem top_mem (X : C) : ⊤ ∈ J X := J.top_mem' X /-- Also known as the stability axiom. -/ @[simp] theorem pullback_stable (f : Y ⟶ X) (hS : S ∈ J X) : S.pullback f ∈ J Y := J.pullback_stable' f hS variable {J} in @[simp] lemma pullback_mem_iff_of_isIso {i : X ⟶ Y} [IsIso i] {S : Sieve Y} : S.pullback i ∈ J _ ↔ S ∈ J _ := by refine ⟨fun H ↦ ?_, J.pullback_stable i⟩ convert J.pullback_stable (inv i) H rw [← Sieve.pullback_comp, IsIso.inv_hom_id, Sieve.pullback_id] theorem transitive (hS : S ∈ J X) (R : Sieve X) (h : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → R.pullback f ∈ J Y) : R ∈ J X := J.transitive' hS R h theorem covering_of_eq_top : S = ⊤ → S ∈ J X := fun h => h.symm ▸ J.top_mem X /-- Given a `GrothendieckTopology` and a set of sieves `s` that is equal, form a new `GrothendieckTopology` whose set of sieves is definitionally equal to `s`. -/ def copy (J : GrothendieckTopology C) (s : ∀ X : C, Set (Sieve X)) (h : J.sieves = s) : GrothendieckTopology C where sieves := s top_mem' := h ▸ J.top_mem' pullback_stable' := h ▸ J.pullback_stable' transitive' := h ▸ J.transitive' @[simp] theorem sieves_copy {J : GrothendieckTopology C} {s : ∀ X : C, Set (Sieve X)} {h : J.sieves = s} : (J.copy s h).sieves = s := rfl @[simp] theorem coe_copy {J : GrothendieckTopology C} {s : ∀ X : C, Set (Sieve X)} {h : J.sieves = s} : ⇑(J.copy s h) = s := rfl theorem copy_eq {J : GrothendieckTopology C} {s : ∀ X : C, Set (Sieve X)} {h : J.sieves = s} : J.copy s h = J := GrothendieckTopology.ext h.symm /-- If `S` is a subset of `R`, and `S` is covering, then `R` is covering as well. See also discussion after [MM92] Chapter III, Section 2, Definition 1. -/ @[stacks 00Z5 "(2)"] theorem superset_covering (Hss : S ≤ R) (sjx : S ∈ J X) : R ∈ J X := by apply J.transitive sjx R fun Y f hf => _ intro Y f hf apply covering_of_eq_top rw [← top_le_iff, ← S.pullback_eq_top_of_mem hf] apply Sieve.pullback_monotone _ Hss /-- The intersection of two covering sieves is covering. See also [MM92] Chapter III, Section 2, Definition 1 (iv). -/ @[stacks 00Z5 "(1)"] theorem intersection_covering (rj : R ∈ J X) (sj : S ∈ J X) : R ⊓ S ∈ J X := by apply J.transitive rj _ fun Y f Hf => _ intro Y f hf rw [Sieve.pullback_inter, R.pullback_eq_top_of_mem hf] simp [sj] @[simp] theorem intersection_covering_iff : R ⊓ S ∈ J X ↔ R ∈ J X ∧ S ∈ J X := ⟨fun h => ⟨J.superset_covering inf_le_left h, J.superset_covering inf_le_right h⟩, fun t => intersection_covering _ t.1 t.2⟩ theorem bind_covering {S : Sieve X} {R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y} (hS : S ∈ J X) (hR : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄ (H : S f), R H ∈ J Y) : Sieve.bind S R ∈ J X := J.transitive hS _ fun _ f hf => superset_covering J (Sieve.le_pullback_bind S R f hf) (hR hf) lemma bindOfArrows {ι : Type*} {X : C} {Z : ι → C} {f : ∀ i, Z i ⟶ X} {R : ∀ i, Presieve (Z i)} (h : Sieve.ofArrows Z f ∈ J X) (hR : ∀ i, Sieve.generate (R i) ∈ J _) : Sieve.generate (Presieve.bindOfArrows Z f R) ∈ J X := by refine J.superset_covering (Presieve.bind_ofArrows_le_bindOfArrows _ _ _) ?_ exact J.bind_covering h fun _ _ _ ↦ J.pullback_stable _ (hR _) /-- The sieve `S` on `X` `J`-covers an arrow `f` to `X` if `S.pullback f ∈ J Y`. This definition is an alternate way of presenting a Grothendieck topology. -/ def Covers (S : Sieve X) (f : Y ⟶ X) : Prop := S.pullback f ∈ J Y theorem covers_iff (S : Sieve X) (f : Y ⟶ X) : J.Covers S f ↔ S.pullback f ∈ J Y := Iff.rfl theorem covering_iff_covers_id (S : Sieve X) : S ∈ J X ↔ J.Covers S (𝟙 X) := by simp [covers_iff] /-- The maximality axiom in 'arrow' form: Any arrow `f` in `S` is covered by `S`. -/ theorem arrow_max (f : Y ⟶ X) (S : Sieve X) (hf : S f) : J.Covers S f := by rw [Covers, (Sieve.mem_iff_pullback_eq_top f).1 hf] apply J.top_mem /-- The stability axiom in 'arrow' form: If `S` covers `f` then `S` covers `g ≫ f` for any `g`. -/ theorem arrow_stable (f : Y ⟶ X) (S : Sieve X) (h : J.Covers S f) {Z : C} (g : Z ⟶ Y) : J.Covers S (g ≫ f) := by rw [covers_iff] at h ⊢ simp [h, Sieve.pullback_comp] /-- The transitivity axiom in 'arrow' form: If `S` covers `f` and every arrow in `S` is covered by `R`, then `R` covers `f`. -/ theorem arrow_trans (f : Y ⟶ X) (S R : Sieve X) (h : J.Covers S f) : (∀ {Z : C} (g : Z ⟶ X), S g → J.Covers R g) → J.Covers R f := by intro k apply J.transitive h intro Z g hg rw [← Sieve.pullback_comp] apply k (g ≫ f) hg theorem arrow_intersect (f : Y ⟶ X) (S R : Sieve X) (hS : J.Covers S f) (hR : J.Covers R f) : J.Covers (S ⊓ R) f := by simpa [covers_iff] using And.intro hS hR variable (C) /-- The trivial Grothendieck topology, in which only the maximal sieve is covering. This topology is also known as the indiscrete, coarse, or chaotic topology. See [MM92] Chapter III, Section 2, example (a), or https://en.wikipedia.org/wiki/Grothendieck_topology#The_discrete_and_indiscrete_topologies -/ def trivial : GrothendieckTopology C where sieves _ := {⊤} top_mem' _ := rfl pullback_stable' X Y S f hf := by rw [Set.mem_singleton_iff] at hf ⊢ simp [hf] transitive' X S hS R hR := by rw [Set.mem_singleton_iff, ← Sieve.id_mem_iff_eq_top] at hS simpa using hR hS /-- The discrete Grothendieck topology, in which every sieve is covering. See https://en.wikipedia.org/wiki/Grothendieck_topology#The_discrete_and_indiscrete_topologies. -/ def discrete : GrothendieckTopology C where sieves _ := Set.univ top_mem' := by simp pullback_stable' X Y f := by simp transitive' := by simp variable {C} theorem trivial_covering : S ∈ trivial C X ↔ S = ⊤ := Set.mem_singleton_iff @[stacks 00Z6] instance instLEGrothendieckTopology : LE (GrothendieckTopology C) where le J₁ J₂ := (J₁ : ∀ X : C, Set (Sieve X)) ≤ (J₂ : ∀ X : C, Set (Sieve X)) theorem le_def {J₁ J₂ : GrothendieckTopology C} : J₁ ≤ J₂ ↔ (J₁ : ∀ X : C, Set (Sieve X)) ≤ J₂ := Iff.rfl @[stacks 00Z6] instance : PartialOrder (GrothendieckTopology C) := { instLEGrothendieckTopology with le_refl := fun _ => le_def.mpr le_rfl le_trans := fun _ _ _ h₁₂ h₂₃ => le_def.mpr (le_trans h₁₂ h₂₃) le_antisymm := fun _ _ h₁₂ h₂₁ => GrothendieckTopology.ext (le_antisymm h₁₂ h₂₁) } @[stacks 00Z7] instance : InfSet (GrothendieckTopology C) where sInf T := { sieves := sInf (sieves '' T) top_mem' := by rintro X S ⟨⟨_, J, hJ, rfl⟩, rfl⟩ simp pullback_stable' := by rintro X Y S hS f _ ⟨⟨_, J, hJ, rfl⟩, rfl⟩ apply J.pullback_stable _ (f _ ⟨⟨_, _, hJ, rfl⟩, rfl⟩) transitive' := by rintro X S hS R h _ ⟨⟨_, J, hJ, rfl⟩, rfl⟩ apply J.transitive (hS _ ⟨⟨_, _, hJ, rfl⟩, rfl⟩) _ fun Y f hf => h hf _ ⟨⟨_, _, hJ, rfl⟩, rfl⟩ } lemma mem_sInf (s : Set (GrothendieckTopology C)) {X : C} (S : Sieve X) : S ∈ sInf s X ↔ ∀ t ∈ s, S ∈ t X := by change S ∈ sInf (sieves '' s) X ↔ _ simp @[stacks 00Z7] theorem isGLB_sInf (s : Set (GrothendieckTopology C)) : IsGLB s (sInf s) := by refine @IsGLB.of_image _ _ _ _ sieves ?_ _ _ ?_ · rfl · exact _root_.isGLB_sInf _ /-- Construct a complete lattice from the `Inf`, but make the trivial and discrete topologies definitionally equal to the bottom and top respectively. -/ instance : CompleteLattice (GrothendieckTopology C) := CompleteLattice.copy (completeLatticeOfInf _ isGLB_sInf) _ rfl (discrete C) (by apply le_antisymm · exact (completeLatticeOfInf _ isGLB_sInf).le_top (discrete C) · intro X S _ apply Set.mem_univ) (trivial C) (by apply le_antisymm · intro X S hS rw [trivial_covering] at hS apply covering_of_eq_top _ hS · exact (completeLatticeOfInf _ isGLB_sInf).bot_le (trivial C)) _ rfl _ rfl _ rfl sInf rfl instance : Inhabited (GrothendieckTopology C) := ⟨⊤⟩ @[simp] theorem trivial_eq_bot : trivial C = ⊥ := rfl @[simp] theorem discrete_eq_top : discrete C = ⊤ := rfl @[simp] theorem bot_covering : S ∈ (⊥ : GrothendieckTopology C) X ↔ S = ⊤ := trivial_covering @[simp] theorem top_covering : S ∈ (⊤ : GrothendieckTopology C) X := ⟨⟩ theorem bot_covers (S : Sieve X) (f : Y ⟶ X) : (⊥ : GrothendieckTopology C).Covers S f ↔ S f := by rw [covers_iff, bot_covering, ← Sieve.mem_iff_pullback_eq_top] @[simp] theorem top_covers (S : Sieve X) (f : Y ⟶ X) : (⊤ : GrothendieckTopology C).Covers S f := by simp [covers_iff] /-- The dense Grothendieck topology. See https://ncatlab.org/nlab/show/dense+topology, or [MM92] Chapter III, Section 2, example (e). -/ def dense : GrothendieckTopology C where sieves X S := ∀ {Y : C} (f : Y ⟶ X), ∃ (Z : _) (g : Z ⟶ Y), S (g ≫ f) top_mem' _ Y _ := ⟨Y, 𝟙 Y, ⟨⟩⟩ pullback_stable' := by intro X Y S h H Z f rcases H (f ≫ h) with ⟨W, g, H'⟩ exact ⟨W, g, by simpa⟩ transitive' := by intro X S H₁ R H₂ Y f rcases H₁ f with ⟨Z, g, H₃⟩ rcases H₂ H₃ (𝟙 Z) with ⟨W, h, H₄⟩ exact ⟨W, h ≫ g, by simpa using H₄⟩ theorem dense_covering : S ∈ dense X ↔ ∀ {Y} (f : Y ⟶ X), ∃ (Z : _) (g : Z ⟶ Y), S (g ≫ f) := Iff.rfl /-- A category satisfies the right Ore condition if any span can be completed to a commutative square. NB. Any category with pullbacks obviously satisfies the right Ore condition, see `right_ore_of_pullbacks`. -/ def RightOreCondition (C : Type u) [Category.{v} C] : Prop := ∀ {X Y Z : C} (yx : Y ⟶ X) (zx : Z ⟶ X), ∃ (W : _) (wy : W ⟶ Y) (wz : W ⟶ Z), wy ≫ yx = wz ≫ zx theorem right_ore_of_pullbacks [Limits.HasPullbacks C] : RightOreCondition C := fun _ _ => ⟨_, _, _, Limits.pullback.condition⟩ /-- The atomic Grothendieck topology: a sieve is covering iff it is nonempty. For the pullback stability condition, we need the right Ore condition to hold. See https://ncatlab.org/nlab/show/atomic+site, or [MM92] Chapter III, Section 2, example (f). -/ def atomic (hro : RightOreCondition C) : GrothendieckTopology C where sieves X S := ∃ (Y : _) (f : Y ⟶ X), S f top_mem' _ := ⟨_, 𝟙 _, ⟨⟩⟩ pullback_stable' := by rintro X Y S h ⟨Z, f, hf⟩ rcases hro h f with ⟨W, g, k, comm⟩ refine ⟨_, g, ?_⟩ simp [comm, hf] transitive' := by rintro X S ⟨Y, f, hf⟩ R h rcases h hf with ⟨Z, g, hg⟩ exact ⟨_, _, hg⟩ /-- `J.Cover X` denotes the poset of covers of `X` with respect to the Grothendieck topology `J`. -/ def Cover (X : C) : Type max u v := { S : Sieve X // S ∈ J X } deriving Preorder namespace Cover variable {J} instance : CoeOut (J.Cover X) (Sieve X) := ⟨fun S => S.1⟩ instance : CoeFun (J.Cover X) fun _ => ∀ ⦃Y⦄ (_ : Y ⟶ X), Prop := ⟨fun S => (S : Sieve X)⟩ theorem condition (S : J.Cover X) : (S : Sieve X) ∈ J X := S.2 @[ext] theorem ext (S T : J.Cover X) (h : ∀ ⦃Y⦄ (f : Y ⟶ X), S f ↔ T f) : S = T := Subtype.ext <| Sieve.ext h instance : OrderTop (J.Cover X) := { (inferInstance : Preorder (J.Cover X)) with top := ⟨⊤, J.top_mem _⟩ le_top := fun _ _ _ _ => by tauto } instance : SemilatticeInf (J.Cover X) := { (inferInstance : Preorder _) with inf := fun S T => ⟨S ⊓ T, J.intersection_covering S.condition T.condition⟩ le_antisymm := fun _ _ h1 h2 => ext _ _ fun {Y} f => ⟨by apply h1, by apply h2⟩ inf_le_left := fun _ _ _ _ hf => hf.1 inf_le_right := fun _ _ _ _ hf => hf.2 le_inf := fun _ _ _ h1 h2 _ _ h => ⟨h1 _ h, h2 _ h⟩ } instance : Inhabited (J.Cover X) := ⟨⊤⟩ /-- An auxiliary structure, used to define `S.index`. -/ @[ext] structure Arrow (S : J.Cover X) where /-- The source of the arrow. -/ Y : C /-- The arrow itself. -/ f : Y ⟶ X /-- The given arrow is contained in the given sieve. -/ hf : S f /-- Relation between two elements in `S.arrow`, the data of which involves a commutative square. -/ @[ext] structure Arrow.Relation {S : J.Cover X} (I₁ I₂ : S.Arrow) where /-- The source of the arrows defining the relation. -/ Z : C /-- The first arrow defining the relation. -/ g₁ : Z ⟶ I₁.Y /-- The second arrow defining the relation. -/ g₂ : Z ⟶ I₂.Y /-- The relation itself. -/ w : g₁ ≫ I₁.f = g₂ ≫ I₂.f := by cat_disch attribute [reassoc] Arrow.Relation.w /-- Given `I : S.Arrow` and a morphism `g : Z ⟶ I.Y`, this is the arrow in `S.Arrow` corresponding to `g ≫ I.f`. -/ @[simps] def Arrow.precomp {S : J.Cover X} (I : S.Arrow) {Z : C} (g : Z ⟶ I.Y) : S.Arrow := ⟨Z, g ≫ I.f, S.1.downward_closed I.hf g⟩ /-- Given `I : S.Arrow` and a morphism `g : Z ⟶ I.Y`, this is the obvious relation from `I.precomp g` to `I`. -/ @[simps] def Arrow.precompRelation {S : J.Cover X} (I : S.Arrow) {Z : C} (g : Z ⟶ I.Y) : (I.precomp g).Relation I where Z := (I.precomp g).Y g₁ := 𝟙 _ g₂ := g /-- Map an `Arrow` along a refinement `S ⟶ T`. -/ @[simps] def Arrow.map {S T : J.Cover X} (I : S.Arrow) (f : S ⟶ T) : T.Arrow := ⟨I.Y, I.f, f.le _ I.hf⟩ /-- Map an `Arrow.Relation` along a refinement `S ⟶ T`. -/ @[simps] def Arrow.Relation.map {S T : J.Cover X} {I₁ I₂ : S.Arrow} (r : I₁.Relation I₂) (f : S ⟶ T) : (I₁.map f).Relation (I₂.map f) := { r with } /-- Pull back a cover along a morphism. -/ def pullback (S : J.Cover X) (f : Y ⟶ X) : J.Cover Y := ⟨Sieve.pullback f S, J.pullback_stable _ S.condition⟩ /-- An arrow of `S.pullback f` gives rise to an arrow of `S`. -/ @[simps] def Arrow.base {f : Y ⟶ X} {S : J.Cover X} (I : (S.pullback f).Arrow) : S.Arrow := ⟨I.Y, I.f ≫ f, I.hf⟩ /-- A relation of `S.pullback f` gives rise to a relation of `S`. -/ def Arrow.Relation.base {f : Y ⟶ X} {S : J.Cover X} {I₁ I₂ : (S.pullback f).Arrow} (r : I₁.Relation I₂) : I₁.base.Relation I₂.base := { r with w := by simp [r.w_assoc] } @[simp] theorem coe_pullback {Z : C} (f : Y ⟶ X) (g : Z ⟶ Y) (S : J.Cover X) : (S.pullback f) g ↔ S (g ≫ f) := Iff.rfl /-- The isomorphism between `S` and the pullback of `S` w.r.t. the identity. -/ def pullbackId (S : J.Cover X) : S.pullback (𝟙 X) ≅ S := eqToIso <| Cover.ext _ _ fun Y f => by simp /-- Pulling back with respect to a composition is the composition of the pullbacks. -/ def pullbackComp {X Y Z : C} (S : J.Cover X) (f : Z ⟶ Y) (g : Y ⟶ X) : S.pullback (f ≫ g) ≅ (S.pullback g).pullback f := eqToIso <| Cover.ext _ _ fun Y f => by simp /-- Combine a family of covers over a cover. -/ def bind {X : C} (S : J.Cover X) (T : ∀ I : S.Arrow, J.Cover I.Y) : J.Cover X := ⟨Sieve.bind S fun Y f hf => T ⟨Y, f, hf⟩, J.bind_covering S.condition fun _ _ _ => (T { Y := _, f := _, hf := _ }).condition⟩ /-- The canonical morphism from `S.bind T` to `T`. -/ def bindToBase {X : C} (S : J.Cover X) (T : ∀ I : S.Arrow, J.Cover I.Y) : S.bind T ⟶ S := homOfLE <| by rintro Y f ⟨Z, e1, e2, h1, _, h3⟩ rw [← h3] apply Sieve.downward_closed exact h1 /-- An arrow in bind has the form `A ⟶ B ⟶ X` where `A ⟶ B` is an arrow in `T I` for some `I`. and `B ⟶ X` is an arrow of `S`. This is the object `B`. -/ noncomputable def Arrow.middle {X : C} {S : J.Cover X} {T : ∀ I : S.Arrow, J.Cover I.Y} (I : (S.bind T).Arrow) : C := I.hf.choose /-- An arrow in bind has the form `A ⟶ B ⟶ X` where `A ⟶ B` is an arrow in `T I` for some `I`. and `B ⟶ X` is an arrow of `S`. This is the hom `A ⟶ B`. -/ noncomputable def Arrow.toMiddleHom {X : C} {S : J.Cover X} {T : ∀ I : S.Arrow, J.Cover I.Y} (I : (S.bind T).Arrow) : I.Y ⟶ I.middle := I.hf.choose_spec.choose /-- An arrow in bind has the form `A ⟶ B ⟶ X` where `A ⟶ B` is an arrow in `T I` for some `I`. and `B ⟶ X` is an arrow of `S`. This is the hom `B ⟶ X`. -/ noncomputable def Arrow.fromMiddleHom {X : C} {S : J.Cover X} {T : ∀ I : S.Arrow, J.Cover I.Y} (I : (S.bind T).Arrow) : I.middle ⟶ X := I.hf.choose_spec.choose_spec.choose theorem Arrow.from_middle_condition {X : C} {S : J.Cover X} {T : ∀ I : S.Arrow, J.Cover I.Y} (I : (S.bind T).Arrow) : S I.fromMiddleHom := I.hf.choose_spec.choose_spec.choose_spec.choose /-- An arrow in bind has the form `A ⟶ B ⟶ X` where `A ⟶ B` is an arrow in `T I` for some `I`. and `B ⟶ X` is an arrow of `S`. This is the hom `B ⟶ X`, as an arrow. -/ noncomputable def Arrow.fromMiddle {X : C} {S : J.Cover X} {T : ∀ I : S.Arrow, J.Cover I.Y} (I : (S.bind T).Arrow) : S.Arrow := ⟨_, I.fromMiddleHom, I.from_middle_condition⟩ theorem Arrow.to_middle_condition {X : C} {S : J.Cover X} {T : ∀ I : S.Arrow, J.Cover I.Y} (I : (S.bind T).Arrow) : (T I.fromMiddle) I.toMiddleHom := I.hf.choose_spec.choose_spec.choose_spec.choose_spec.1 /-- An arrow in bind has the form `A ⟶ B ⟶ X` where `A ⟶ B` is an arrow in `T I` for some `I`. and `B ⟶ X` is an arrow of `S`. This is the hom `A ⟶ B`, as an arrow. -/ noncomputable def Arrow.toMiddle {X : C} {S : J.Cover X} {T : ∀ I : S.Arrow, J.Cover I.Y} (I : (S.bind T).Arrow) : (T I.fromMiddle).Arrow := ⟨_, I.toMiddleHom, I.to_middle_condition⟩ theorem Arrow.middle_spec {X : C} {S : J.Cover X} {T : ∀ I : S.Arrow, J.Cover I.Y} (I : (S.bind T).Arrow) : I.toMiddleHom ≫ I.fromMiddleHom = I.f := I.hf.choose_spec.choose_spec.choose_spec.choose_spec.2 /-- An auxiliary structure, used to define `S.index`. -/ @[ext] structure Relation (S : J.Cover X) where /-- The first arrow. -/ {fst : S.Arrow} /-- The second arrow. -/ {snd : S.Arrow} /-- The relation between the two arrows. -/ r : fst.Relation snd /-- Constructor for `Cover.Relation` which takes as an input `r : I₁.Relation I₂` with `I₁ I₂ : S.Arrow`. -/ @[simps] def Relation.mk' {S : J.Cover X} {fst snd : S.Arrow} (r : fst.Relation snd) : S.Relation where fst := fst snd := snd r := r /-- The shape of the multiequalizer diagrams associated to `S : J.Cover X`. -/ @[simps] def shape (S : J.Cover X) : Limits.MulticospanShape where L := S.Arrow R := S.Relation fst I := I.fst snd I := I.snd -- This is used extensively in `Plus.lean`, etc. -- We place this definition here as it will be used in `Sheaf.lean` as well. /-- To every `S : J.Cover X` and presheaf `P`, associate a `MulticospanIndex`. -/ @[simps] def index {D : Type u₁} [Category.{v₁} D] (S : J.Cover X) (P : Cᵒᵖ ⥤ D) : Limits.MulticospanIndex S.shape D where left I := P.obj (Opposite.op I.Y) right I := P.obj (Opposite.op I.r.Z) fst I := P.map I.r.g₁.op snd I := P.map I.r.g₂.op /-- The natural multifork associated to `S : J.Cover X` for a presheaf `P`. Saying that this multifork is a limit is essentially equivalent to the sheaf condition at the given object for the given covering sieve. See `Sheaf.lean` for an equivalent sheaf condition using this. -/ abbrev multifork {D : Type u₁} [Category.{v₁} D] (S : J.Cover X) (P : Cᵒᵖ ⥤ D) : Limits.Multifork (S.index P) := Limits.Multifork.ofι _ (P.obj (Opposite.op X)) (fun I => P.map I.f.op) (by intro I dsimp simp only [← P.map_comp, ← op_comp, I.r.w]) /-- The canonical map from `P.obj (op X)` to the multiequalizer associated to a covering sieve, assuming such a multiequalizer exists. This will be used in `Sheaf.lean` to provide an equivalent sheaf condition in terms of multiequalizers. -/ noncomputable abbrev toMultiequalizer {D : Type u₁} [Category.{v₁} D] (S : J.Cover X) (P : Cᵒᵖ ⥤ D) [Limits.HasMultiequalizer (S.index P)] : P.obj (Opposite.op X) ⟶ Limits.multiequalizer (S.index P) := Limits.Multiequalizer.lift _ _ (fun I => P.map I.f.op) (by intro I dsimp only [shape, index, Relation.fst, Relation.snd] simp only [← P.map_comp, ← op_comp, I.r.w]) end Cover /-- Pull back a cover along a morphism. -/ @[simps obj] def pullback (f : Y ⟶ X) : J.Cover X ⥤ J.Cover Y where obj S := S.pullback f map f := (Sieve.pullback_monotone _ f.le).hom /-- Pulling back along the identity is naturally isomorphic to the identity functor. -/ def pullbackId (X : C) : J.pullback (𝟙 X) ≅ 𝟭 _ := NatIso.ofComponents fun S => S.pullbackId /-- Pulling back along a composition is naturally isomorphic to the composition of the pullbacks. -/ def pullbackComp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : J.pullback (f ≫ g) ≅ J.pullback g ⋙ J.pullback f := NatIso.ofComponents fun S => S.pullbackComp f g end GrothendieckTopology end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Types.lean
import Mathlib.CategoryTheory.Sites.Canonical /-! # Grothendieck Topology and Sheaves on the Category of Types In this file we define a Grothendieck topology on the category of types, and construct the canonical functor that sends a type to a sheaf over the category of types, and make this an equivalence of categories. Then we prove that the topology defined is the canonical topology. -/ universe u namespace CategoryTheory /-- A Grothendieck topology associated to the category of all types. A sieve is a covering iff it is jointly surjective. -/ def typesGrothendieckTopology : GrothendieckTopology (Type u) where sieves α S := ∀ x : α, S fun _ : PUnit => x top_mem' _ _ := trivial pullback_stable' _ _ _ f hs x := hs (f x) transitive' _ _ hs _ hr x := hr (hs x) PUnit.unit /-- The discrete sieve on a type, which only includes arrows whose image is a subsingleton. -/ @[simps] def discreteSieve (α : Type u) : Sieve α where arrows _ f := ∃ x, ∀ y, f y = x downward_closed := fun ⟨x, hx⟩ g => ⟨x, fun y => hx <| g y⟩ theorem discreteSieve_mem (α : Type u) : discreteSieve α ∈ typesGrothendieckTopology α := fun x => ⟨x, fun _ => rfl⟩ /-- The discrete presieve on a type, which only includes arrows whose domain is a singleton. -/ def discretePresieve (α : Type u) : Presieve α := fun β _ => ∃ x : β, ∀ y : β, y = x theorem generate_discretePresieve_mem (α : Type u) : Sieve.generate (discretePresieve α) ∈ typesGrothendieckTopology α := fun x => ⟨PUnit, id, fun _ => x, ⟨PUnit.unit, fun _ => Subsingleton.elim _ _⟩, rfl⟩ /-- The sheaf condition for `yoneda'`. -/ theorem Presieve.isSheaf_yoneda' {α : Type u} : Presieve.IsSheaf typesGrothendieckTopology (yoneda.obj α) := fun β _ hs x hx => ⟨fun y => x _ (hs y) PUnit.unit, fun γ f h => funext fun z => by convert congr_fun (hx (𝟙 _) (fun _ => z) (hs <| f z) h rfl) PUnit.unit using 1, fun f hf => funext fun y => by convert congr_fun (hf _ (hs y)) PUnit.unit⟩ /-- The sheaf condition for `yoneda'`. -/ theorem Presheaf.isSheaf_yoneda' {α : Type u} : Presheaf.IsSheaf typesGrothendieckTopology (yoneda.obj α) := by rw [isSheaf_iff_isSheaf_of_type] exact Presieve.isSheaf_yoneda' /-- The yoneda functor that sends a type to a sheaf over the category of types. -/ @[simps] def yoneda' : Type u ⥤ Sheaf typesGrothendieckTopology (Type u) where obj α := ⟨yoneda.obj α, Presheaf.isSheaf_yoneda'⟩ map f := ⟨yoneda.map f⟩ @[simp] theorem yoneda'_comp : yoneda'.{u} ⋙ sheafToPresheaf _ _ = yoneda := rfl open Opposite /-- Given a presheaf `P` on the category of types, construct a map `P(α) → (α → P(*))` for all type `α`. -/ def eval (P : Type uᵒᵖ ⥤ Type u) (α : Type u) (s : P.obj (op α)) (x : α) : P.obj (op PUnit) := P.map (↾fun _ => x).op s open Presieve /-- Given a sheaf `S` on the category of types, construct a map `(α → S(*)) → S(α)` that is inverse to `eval`. -/ noncomputable def typesGlue (S : Type uᵒᵖ ⥤ Type u) (hs : IsSheaf typesGrothendieckTopology S) (α : Type u) (f : α → S.obj (op PUnit)) : S.obj (op α) := (hs.isSheafFor _ _ (generate_discretePresieve_mem α)).amalgamate (fun _ g hg => S.map (↾fun _ => PUnit.unit).op <| f <| g <| Classical.choose hg) fun β γ δ g₁ g₂ f₁ f₂ hf₁ hf₂ h => (hs.isSheafFor _ _ (generate_discretePresieve_mem δ)).isSeparatedFor.ext fun ε g ⟨x, _⟩ => by have : f₁ (Classical.choose hf₁) = f₂ (Classical.choose hf₂) := Classical.choose_spec hf₁ (g₁ <| g x) ▸ Classical.choose_spec hf₂ (g₂ <| g x) ▸ congr_fun h _ simp_rw [← FunctorToTypes.map_comp_apply, this, ← op_comp] rfl theorem eval_typesGlue {S hs α} (f) : eval.{u} S α (typesGlue S hs α f) = f := by funext x apply (IsSheafFor.valid_glue _ _ _ <| ⟨PUnit.unit, fun _ => Subsingleton.elim _ _⟩).trans convert FunctorToTypes.map_id_apply S _ theorem typesGlue_eval {S hs α} (s) : typesGlue.{u} S hs α (eval S α s) = s := by apply (hs.isSheafFor _ _ (generate_discretePresieve_mem α)).isSeparatedFor.ext intro β f hf apply (IsSheafFor.valid_glue _ _ _ hf).trans apply (FunctorToTypes.map_comp_apply _ _ _ _).symm.trans rw [← op_comp] --congr 2 -- Porting note: This tactic didn't work. Find an alternative. suffices ((↾fun _ ↦ PUnit.unit) ≫ ↾fun _ ↦ f (Classical.choose hf)) = f by rw [this] funext x exact congr_arg f (Classical.choose_spec hf x).symm /-- Given a sheaf `S`, construct an equivalence `S(α) ≃ (α → S(*))`. -/ @[simps] noncomputable def evalEquiv (S : Type uᵒᵖ ⥤ Type u) (hs : Presheaf.IsSheaf typesGrothendieckTopology S) (α : Type u) : S.obj (op α) ≃ (α → S.obj (op PUnit)) where toFun := eval S α invFun := typesGlue S ((isSheaf_iff_isSheaf_of_type _ _ ).1 hs) α left_inv := typesGlue_eval right_inv := eval_typesGlue theorem eval_map (S : Type uᵒᵖ ⥤ Type u) (α β) (f : β ⟶ α) (s x) : eval S β (S.map f.op s) x = eval S α s (f x) := by simp_rw [eval, ← FunctorToTypes.map_comp_apply, ← op_comp]; rfl /-- Given a sheaf `S`, construct an isomorphism `S ≅ [-, S(*)]`. -/ @[simps!] noncomputable def equivYoneda (S : Type uᵒᵖ ⥤ Type u) (hs : Presheaf.IsSheaf typesGrothendieckTopology S) : S ≅ yoneda.obj (S.obj (op PUnit)) := NatIso.ofComponents (fun α => Equiv.toIso <| evalEquiv S hs <| unop α) fun {α β} f => funext fun _ => funext fun _ => eval_map S (unop α) (unop β) f.unop _ _ /-- Given a sheaf `S`, construct an isomorphism `S ≅ [-, S(*)]`. -/ @[simps] noncomputable def equivYoneda' (S : Sheaf typesGrothendieckTopology (Type u)) : S ≅ yoneda'.obj (S.1.obj (op PUnit)) where hom := ⟨(equivYoneda S.1 S.2).hom⟩ inv := ⟨(equivYoneda S.1 S.2).inv⟩ hom_inv_id := by ext1; apply (equivYoneda S.1 S.2).hom_inv_id inv_hom_id := by ext1; apply (equivYoneda S.1 S.2).inv_hom_id theorem eval_app (S₁ S₂ : Sheaf typesGrothendieckTopology (Type u)) (f : S₁ ⟶ S₂) (α : Type u) (s : S₁.1.obj (op α)) (x : α) : eval S₂.1 α (f.val.app (op α) s) x = f.val.app (op PUnit) (eval S₁.1 α s x) := (congr_fun (f.val.naturality (↾fun _ : PUnit => x).op) s).symm /-- `yoneda'` induces an equivalence of category between `Type u` and `Sheaf typesGrothendieckTopology (Type u)`. -/ @[simps!] noncomputable def typeEquiv : Type u ≌ Sheaf typesGrothendieckTopology (Type u) where functor := yoneda' inverse := sheafToPresheaf _ _ ⋙ (evaluation _ _).obj (op PUnit) unitIso := NatIso.ofComponents (fun _α => -- α ≅ PUnit ⟶ α { hom := fun x _ => x inv := fun f => f PUnit.unit hom_inv_id := funext fun _ => rfl inv_hom_id := funext fun _ => funext fun y => PUnit.casesOn y rfl }) fun _ => rfl counitIso := Iso.symm <| NatIso.ofComponents (fun S => equivYoneda' S) (fun {S₁ S₂} f => by ext ⟨α⟩ s dsimp at s ⊢ ext x exact eval_app S₁ S₂ f α s x) functor_unitIso_comp X := by ext1 apply yonedaEquiv.injective dsimp [yoneda', yonedaEquiv, evalEquiv] erw [typesGlue_eval] instance subcanonical_typesGrothendieckTopology : typesGrothendieckTopology.{u}.Subcanonical := GrothendieckTopology.Subcanonical.of_isSheaf_yoneda_obj _ fun _ => Presieve.isSheaf_yoneda' theorem typesGrothendieckTopology_eq_canonical : typesGrothendieckTopology.{u} = Sheaf.canonicalTopology (Type u) := by refine le_antisymm typesGrothendieckTopology.le_canonical (sInf_le ?_) refine ⟨yoneda.obj (ULift Bool), ⟨_, rfl⟩, GrothendieckTopology.ext ?_⟩ funext α ext S refine ⟨fun hs x => ?_, fun hs β f => Presieve.isSheaf_yoneda' _ fun y => hs _⟩ by_contra hsx have : (fun _ => ULift.up true) = fun _ => ULift.up false := (hs PUnit fun _ => x).isSeparatedFor.ext fun β f hf => funext fun y => hsx.elim <| S.2 hf fun _ => y simp [funext_iff] at this end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Whiskering.lean
import Mathlib.CategoryTheory.Sites.Sheaf /-! In this file we construct the functor `Sheaf J A ⥤ Sheaf J B` between sheaf categories obtained by composition with a functor `F : A ⥤ B`. In order for the sheaf condition to be preserved, `F` must preserve the correct limits. The lemma `Presheaf.IsSheaf.comp` says that composition with such an `F` indeed preserves the sheaf condition. The functor between sheaf categories is called `sheafCompose J F`. Given a natural transformation `η : F ⟶ G`, we obtain a natural transformation `sheafCompose J F ⟶ sheafCompose J G`, which we call `sheafCompose_map J η`. -/ namespace CategoryTheory open CategoryTheory.Limits Functor universe v₁ v₂ v₃ u₁ u₂ u₃ variable {C : Type u₁} [Category.{v₁} C] variable {A : Type u₂} [Category.{v₂} A] variable {B : Type u₃} [Category.{v₃} B] variable (J : GrothendieckTopology C) variable {U : C} (R : Presieve U) variable (F G H : A ⥤ B) (η : F ⟶ G) (γ : G ⟶ H) /-- Describes the property of a functor to "preserve sheaves". -/ class GrothendieckTopology.HasSheafCompose : Prop where /-- For every sheaf `P`, `P ⋙ F` is a sheaf. -/ isSheaf (P : Cᵒᵖ ⥤ A) (hP : Presheaf.IsSheaf J P) : Presheaf.IsSheaf J (P ⋙ F) variable [J.HasSheafCompose F] [J.HasSheafCompose G] [J.HasSheafCompose H] /-- Composing a functor which `HasSheafCompose`, yields a functor between sheaf categories. -/ @[simps] def sheafCompose : Sheaf J A ⥤ Sheaf J B where obj G := ⟨G.val ⋙ F, GrothendieckTopology.HasSheafCompose.isSheaf G.val G.2⟩ map η := ⟨whiskerRight η.val _⟩ map_id _ := Sheaf.Hom.ext <| whiskerRight_id _ map_comp _ _ := Sheaf.Hom.ext <| whiskerRight_comp _ _ _ instance [F.Faithful] : (sheafCompose J F ⋙ sheafToPresheaf _ _).Faithful := show (sheafToPresheaf _ _ ⋙ (whiskeringRight Cᵒᵖ A B).obj F).Faithful from inferInstance instance [F.Faithful] [F.Full] : (sheafCompose J F ⋙ sheafToPresheaf _ _).Full := show (sheafToPresheaf _ _ ⋙ (whiskeringRight Cᵒᵖ A B).obj F).Full from inferInstance instance [F.Faithful] : (sheafCompose J F).Faithful := Functor.Faithful.of_comp (sheafCompose J F) (sheafToPresheaf _ _) instance [F.Full] [F.Faithful] : (sheafCompose J F).Full := Functor.Full.of_comp_faithful (sheafCompose J F) (sheafToPresheaf _ _) instance [F.ReflectsIsomorphisms] : (sheafCompose J F).ReflectsIsomorphisms where reflects {G₁ G₂} f _ := by rw [← isIso_iff_of_reflects_iso _ (sheafToPresheaf _ _), ← isIso_iff_of_reflects_iso _ ((whiskeringRight Cᵒᵖ A B).obj F)] change IsIso ((sheafToPresheaf _ _).map ((sheafCompose J F).map f)) infer_instance variable {F G} /-- If `η : F ⟶ G` is a natural transformation then we obtain a morphism of functors `sheafCompose J F ⟶ sheafCompose J G` by whiskering with `η` on the level of presheaves. -/ def sheafCompose_map : sheafCompose J F ⟶ sheafCompose J G where app := fun _ => .mk <| whiskerLeft _ η @[simp] lemma sheafCompose_id : sheafCompose_map (F := F) J (𝟙 _) = 𝟙 _ := rfl @[simp] lemma sheafCompose_comp : sheafCompose_map J (η ≫ γ) = sheafCompose_map J η ≫ sheafCompose_map J γ := rfl namespace GrothendieckTopology.Cover variable (F G) {J} variable (P : Cᵒᵖ ⥤ A) {X : C} (S : J.Cover X) /-- The multicospan associated to a cover `S : J.Cover X` and a presheaf of the form `P ⋙ F` is isomorphic to the composition of the multicospan associated to `S` and `P`, composed with `F`. -/ @[simps!] def multicospanComp : (S.index (P ⋙ F)).multicospan ≅ (S.index P).multicospan ⋙ F := NatIso.ofComponents (fun t => match t with | WalkingMulticospan.left _ => Iso.refl _ | WalkingMulticospan.right _ => Iso.refl _) (by rintro (a | b) (a | b) (f | f | f) all_goals cat_disch) /-- Mapping the multifork associated to a cover `S : J.Cover X` and a presheaf `P` with respect to a functor `F` is isomorphic (upto a natural isomorphism of the underlying functors) to the multifork associated to `S` and `P ⋙ F`. -/ def mapMultifork : F.mapCone (S.multifork P) ≅ (Limits.Cones.postcompose (S.multicospanComp F P).hom).obj (S.multifork (P ⋙ F)) := Cones.ext (Iso.refl _) end GrothendieckTopology.Cover /-- Composing a sheaf with a functor preserving the limit of `(S.index P).multicospan` yields a functor between sheaf categories. -/ instance (priority := high) hasSheafCompose_of_preservesMulticospan (F : A ⥤ B) [∀ (X : C) (S : J.Cover X) (P : Cᵒᵖ ⥤ A), PreservesLimit (S.index P).multicospan F] : J.HasSheafCompose F where isSheaf P hP := by rw [Presheaf.isSheaf_iff_multifork] at hP ⊢ intro X S obtain ⟨h⟩ := hP X S replace h := isLimitOfPreserves F h replace h := Limits.IsLimit.ofIsoLimit h (S.mapMultifork F P) exact ⟨Limits.IsLimit.postcomposeHomEquiv (S.multicospanComp F P) _ h⟩ /-- Composing a sheaf with a functor preserving limits of the same size as the hom sets in `C` yields a functor between sheaf categories. Note: the size of the limit that `F` is required to preserve in `hasSheafCompose_of_preservesMulticospan` is in general larger than this. -/ instance hasSheafCompose_of_preservesLimitsOfSize [PreservesLimitsOfSize.{v₁, max u₁ v₁} F] : J.HasSheafCompose F where isSheaf _ hP := Presheaf.isSheaf_comp_of_isSheaf J _ F hP variable {J} lemma Sheaf.isSeparated {FA : A → A → Type*} {CA : A → Type*} [∀ X Y, FunLike (FA X Y) (CA X) (CA Y)] [ConcreteCategory A FA] [J.HasSheafCompose (forget A)] (F : Sheaf J A) : Presheaf.IsSeparated J F.val := by rintro X S hS x y h exact (((isSheaf_iff_isSheaf_of_type _ _).1 ((sheafCompose J (forget A)).obj F).2).isSeparated S hS).ext (fun _ _ hf => h _ _ hf) lemma Presheaf.IsSheaf.isSeparated {F : Cᵒᵖ ⥤ A} {FA : A → A → Type*} {CA : A → Type*} [∀ X Y, FunLike (FA X Y) (CA X) (CA Y)] [ConcreteCategory A FA] [J.HasSheafCompose (forget A)] (hF : Presheaf.IsSheaf J F) : Presheaf.IsSeparated J F := Sheaf.isSeparated ⟨F, hF⟩ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Limits.lean
import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Sites.Sheafification import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts /-! # Limits and colimits of sheaves ## Limits We prove that the forgetful functor from `Sheaf J D` to presheaves creates limits. If the target category `D` has limits (of a certain shape), this then implies that `Sheaf J D` has limits of the same shape and that the forgetful functor preserves these limits. ## Colimits Given a diagram `F : K ⥤ Sheaf J D` of sheaves, and a colimit cocone on the level of presheaves, we show that the cocone obtained by sheafifying the cocone point is a colimit cocone of sheaves. This allows us to show that `Sheaf J D` has colimits (of a certain shape) as soon as `D` does. -/ namespace CategoryTheory namespace Sheaf open CategoryTheory.Limits open Opposite universe w w' v u z z' u₁ u₂ variable {C : Type u} [Category.{v} C] {J : GrothendieckTopology C} variable {D : Type w} [Category.{w'} D] variable {K : Type z} [Category.{z'} K] section Limits noncomputable section section /-- An auxiliary definition to be used below. Whenever `E` is a cone of shape `K` of sheaves, and `S` is the multifork associated to a covering `W` of an object `X`, with respect to the cone point `E.X`, this provides a cone of shape `K` of objects in `D`, with cone point `S.X`. See `isLimitMultiforkOfIsLimit` for more on how this definition is used. -/ def multiforkEvaluationCone (F : K ⥤ Sheaf J D) (E : Cone (F ⋙ sheafToPresheaf J D)) (X : C) (W : J.Cover X) (S : Multifork (W.index E.pt)) : Cone (F ⋙ sheafToPresheaf J D ⋙ (evaluation Cᵒᵖ D).obj (op X)) where pt := S.pt π := { app := fun k => (Presheaf.isLimitOfIsSheaf J (F.obj k).1 W (F.obj k).2).lift <| Multifork.ofι _ S.pt (fun i => S.ι i ≫ (E.π.app k).app (op i.Y)) (by intro i simp only [Category.assoc] erw [← (E.π.app k).naturality, ← (E.π.app k).naturality] dsimp simp only [← Category.assoc] congr 1 apply S.condition) naturality := by intro i j f dsimp [Presheaf.isLimitOfIsSheaf] rw [Category.id_comp] apply Presheaf.IsSheaf.hom_ext (F.obj j).2 W intro ii rw [Presheaf.IsSheaf.amalgamate_map, Category.assoc, ← (F.map f).val.naturality, ← Category.assoc, Presheaf.IsSheaf.amalgamate_map] dsimp [Multifork.ofι] erw [Category.assoc, ← E.w f] cat_disch } variable [HasLimitsOfShape K D] /-- If `E` is a cone of shape `K` of sheaves, which is a limit on the level of presheaves, this definition shows that the limit presheaf satisfies the multifork variant of the sheaf condition, at a given covering `W`. This is used below in `isSheaf_of_isLimit` to show that the limit presheaf is indeed a sheaf. -/ def isLimitMultiforkOfIsLimit (F : K ⥤ Sheaf J D) (E : Cone (F ⋙ sheafToPresheaf J D)) (hE : IsLimit E) (X : C) (W : J.Cover X) : IsLimit (W.multifork E.pt) := Multifork.IsLimit.mk _ (fun S => (isLimitOfPreserves ((evaluation Cᵒᵖ D).obj (op X)) hE).lift <| multiforkEvaluationCone F E X W S) (by intro S i apply (isLimitOfPreserves ((evaluation Cᵒᵖ D).obj (op i.Y)) hE).hom_ext intro k dsimp [Multifork.ofι] erw [Category.assoc, (E.π.app k).naturality] dsimp rw [← Category.assoc] erw [(isLimitOfPreserves ((evaluation Cᵒᵖ D).obj (op X)) hE).fac (multiforkEvaluationCone F E X W S)] dsimp [multiforkEvaluationCone, Presheaf.isLimitOfIsSheaf] rw [Presheaf.IsSheaf.amalgamate_map] rfl) (by intro S m hm apply (isLimitOfPreserves ((evaluation Cᵒᵖ D).obj (op X)) hE).hom_ext intro k dsimp erw [(isLimitOfPreserves ((evaluation Cᵒᵖ D).obj (op X)) hE).fac] apply Presheaf.IsSheaf.hom_ext (F.obj k).2 W intro i dsimp only [multiforkEvaluationCone, Presheaf.isLimitOfIsSheaf] rw [(F.obj k).cond.amalgamate_map] dsimp [Multifork.ofι] change _ = S.ι i ≫ _ erw [← hm, Category.assoc, ← (E.π.app k).naturality, Category.assoc] rfl) /-- If `E` is a cone which is a limit on the level of presheaves, then the limit presheaf is again a sheaf. This is used to show that the forgetful functor from sheaves to presheaves creates limits. -/ theorem isSheaf_of_isLimit (F : K ⥤ Sheaf J D) (E : Cone (F ⋙ sheafToPresheaf J D)) (hE : IsLimit E) : Presheaf.IsSheaf J E.pt := by rw [Presheaf.isSheaf_iff_multifork] intro X S exact ⟨isLimitMultiforkOfIsLimit _ _ hE _ _⟩ instance (F : K ⥤ Sheaf J D) : CreatesLimit F (sheafToPresheaf J D) := createsLimitOfReflectsIso fun E hE => { liftedCone := ⟨⟨E.pt, isSheaf_of_isLimit _ _ hE⟩, ⟨fun _ => ⟨E.π.app _⟩, fun _ _ _ => Sheaf.Hom.ext <| E.π.naturality _⟩⟩ validLift := Cones.ext (eqToIso rfl) fun j => by simp makesLimit := { lift := fun S => ⟨hE.lift ((sheafToPresheaf J D).mapCone S)⟩ fac := fun S j => by ext1 apply hE.fac ((sheafToPresheaf J D).mapCone S) j uniq := fun S m hm => by ext1 exact hE.uniq ((sheafToPresheaf J D).mapCone S) m.val fun j => congr_arg Hom.val (hm j) } } instance createsLimitsOfShape : CreatesLimitsOfShape K (sheafToPresheaf J D) where instance : HasLimitsOfShape K (Sheaf J D) := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape (sheafToPresheaf J D) instance [HasFiniteProducts D] : HasFiniteProducts (Sheaf J D) := ⟨inferInstance⟩ instance [HasFiniteLimits D] : HasFiniteLimits (Sheaf J D) := ⟨fun _ ↦ inferInstance⟩ end instance createsLimits [HasLimitsOfSize.{u₁, u₂} D] : CreatesLimitsOfSize.{u₁, u₂} (sheafToPresheaf J D) := ⟨createsLimitsOfShape⟩ instance hasLimitsOfSize [HasLimitsOfSize.{u₁, u₂} D] : HasLimitsOfSize.{u₁, u₂} (Sheaf J D) := hasLimits_of_hasLimits_createsLimits (sheafToPresheaf J D) variable {D : Type w} [Category.{max v u} D] example [HasLimits D] : HasLimits (Sheaf J D) := inferInstance end end Limits section Colimits variable [HasWeakSheafify J D] /-- Construct a cocone by sheafifying a cocone point of a cocone `E` of presheaves over a functor which factors through sheaves. In `isColimitSheafifyCocone`, we show that this is a colimit cocone when `E` is a colimit. -/ noncomputable def sheafifyCocone {F : K ⥤ Sheaf J D} (E : Cocone (F ⋙ sheafToPresheaf J D)) : Cocone F := (Cocones.precompose (Functor.isoWhiskerLeft F (asIso (sheafificationAdjunction J D).counit).symm).hom).obj ((presheafToSheaf J D).mapCocone E) /-- If `E` is a colimit cocone of presheaves, over a diagram factoring through sheaves, then `sheafifyCocone E` is a colimit cocone. -/ noncomputable def isColimitSheafifyCocone {F : K ⥤ Sheaf J D} (E : Cocone (F ⋙ sheafToPresheaf J D)) (hE : IsColimit E) : IsColimit (sheafifyCocone E) := (IsColimit.precomposeHomEquiv _ ((presheafToSheaf J D).mapCocone E)).symm (isColimitOfPreserves _ hE) instance [HasColimitsOfShape K D] : HasColimitsOfShape K (Sheaf J D) := ⟨fun _ => HasColimit.mk ⟨sheafifyCocone (colimit.cocone _), isColimitSheafifyCocone _ (colimit.isColimit _)⟩⟩ instance [HasFiniteCoproducts D] : HasFiniteCoproducts (Sheaf J D) := ⟨inferInstance⟩ instance [HasFiniteColimits D] : HasFiniteColimits (Sheaf J D) := ⟨fun _ ↦ inferInstance⟩ instance [HasColimitsOfSize.{u₁, u₂} D] : HasColimitsOfSize.{u₁, u₂} (Sheaf J D) := ⟨inferInstance⟩ /-- If every cocone on a diagram of sheaves which is a colimit on the level of presheaves satisfies the condition that the cocone point is a sheaf, then the functor from sheaves to presheaves creates colimits of the diagram. Note: this almost never holds in sheaf categories in general, but it does for the extensive topology (see `Mathlib/CategoryTheory/Sites/Coherent/ExtensiveColimits.lean`). -/ def createsColimitOfIsSheaf (F : K ⥤ Sheaf J D) (h : ∀ (c : Cocone (F ⋙ sheafToPresheaf J D)) (_ : IsColimit c), Presheaf.IsSheaf J c.pt) : CreatesColimit F (sheafToPresheaf J D) := createsColimitOfReflectsIso fun E hE => { liftedCocone := ⟨⟨E.pt, h _ hE⟩, ⟨fun _ => ⟨E.ι.app _⟩, fun _ _ _ => Sheaf.Hom.ext <| E.ι.naturality _⟩⟩ validLift := Cocones.ext (eqToIso rfl) fun j => by simp makesColimit := { desc := fun S => ⟨hE.desc ((sheafToPresheaf J D).mapCocone S)⟩ fac := fun S j => by ext1; dsimp; rw [hE.fac]; rfl uniq := fun S m hm => by ext1 exact hE.uniq ((sheafToPresheaf J D).mapCocone S) m.val fun j => congr_arg Hom.val (hm j) } } variable {D : Type w} [Category.{max v u} D] example [HasLimits D] : HasLimits (Sheaf J D) := inferInstance end Colimits end Sheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Closed.lean
import Mathlib.CategoryTheory.Sites.SheafOfTypes import Mathlib.Order.Closure /-! # Closed sieves A natural closure operator on sieves is a closure operator on `Sieve X` for each `X` which commutes with pullback. We show that a Grothendieck topology `J` induces a natural closure operator, and define what the closed sieves are. The collection of `J`-closed sieves forms a presheaf which is a sheaf for `J`, and further this presheaf can be used to determine the Grothendieck topology from the sheaf predicate. Finally we show that a natural closure operator on sieves induces a Grothendieck topology, and hence that natural closure operators are in bijection with Grothendieck topologies. ## Main definitions * `CategoryTheory.GrothendieckTopology.close`: Sends a sieve `S` on `X` to the set of arrows which it covers. This has all the usual properties of a closure operator, as well as commuting with pullback. * `CategoryTheory.GrothendieckTopology.closureOperator`: The bundled `ClosureOperator` given by `CategoryTheory.GrothendieckTopology.close`. * `CategoryTheory.GrothendieckTopology.IsClosed`: A sieve `S` on `X` is closed for the topology `J` if it contains every arrow it covers. * `CategoryTheory.Functor.closedSieves`: The presheaf sending `X` to the collection of `J`-closed sieves on `X`. This is additionally shown to be a sheaf for `J`, and if this is a sheaf for a different topology `J'`, then `J' ≤ J`. * `CategoryTheory.topologyOfClosureOperator`: A closure operator on the set of sieves on every object which commutes with pullback additionally induces a Grothendieck topology, giving a bijection with `CategoryTheory.GrothendieckTopology.closureOperator`. ## Tags closed sieve, closure, Grothendieck topology ## References * [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92] -/ universe v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] variable (J₁ J₂ : GrothendieckTopology C) namespace GrothendieckTopology /-- The `J`-closure of a sieve is the collection of arrows which it covers. -/ @[simps] def close {X : C} (S : Sieve X) : Sieve X where arrows _ f := J₁.Covers S f downward_closed hS := J₁.arrow_stable _ _ hS /-- Any sieve is smaller than its closure. -/ theorem le_close {X : C} (S : Sieve X) : S ≤ J₁.close S := fun _ _ hg => J₁.covering_of_eq_top (S.pullback_eq_top_of_mem hg) /-- A sieve is closed for the Grothendieck topology if it contains every arrow it covers. In the case of the usual topology on a topological space, this means that the open cover contains every open set which it covers. Note this has no relation to a closed subset of a topological space. -/ def IsClosed {X : C} (S : Sieve X) : Prop := ∀ ⦃Y : C⦄ (f : Y ⟶ X), J₁.Covers S f → S f /-- If `S` is `J₁`-closed, then `S` covers exactly the arrows it contains. -/ theorem covers_iff_mem_of_isClosed {X : C} {S : Sieve X} (h : J₁.IsClosed S) {Y : C} (f : Y ⟶ X) : J₁.Covers S f ↔ S f := ⟨h _, J₁.arrow_max _ _⟩ /-- Being `J`-closed is stable under pullback. -/ theorem isClosed_pullback {X Y : C} (f : Y ⟶ X) (S : Sieve X) : J₁.IsClosed S → J₁.IsClosed (S.pullback f) := fun hS Z g hg => hS (g ≫ f) (by rwa [J₁.covers_iff, Sieve.pullback_comp]) /-- The closure of a sieve `S` is the largest closed sieve which contains `S` (justifying the name "closure"). -/ theorem le_close_of_isClosed {X : C} {S T : Sieve X} (h : S ≤ T) (hT : J₁.IsClosed T) : J₁.close S ≤ T := fun _ f hf => hT _ (J₁.superset_covering (Sieve.pullback_monotone f h) hf) /-- The closure of a sieve is closed. -/ theorem close_isClosed {X : C} (S : Sieve X) : J₁.IsClosed (J₁.close S) := fun _ g hg => J₁.arrow_trans g _ S hg fun _ hS => hS /-- A Grothendieck topology induces a natural family of closure operators on sieves. -/ @[simps! isClosed] def closureOperator (X : C) : ClosureOperator (Sieve X) := .ofPred J₁.close J₁.IsClosed J₁.le_close J₁.close_isClosed fun _ _ ↦ J₁.le_close_of_isClosed /-- The sieve `S` is closed iff its closure is equal to itself. -/ theorem isClosed_iff_close_eq_self {X : C} (S : Sieve X) : J₁.IsClosed S ↔ J₁.close S = S := (J₁.closureOperator _).isClosed_iff theorem close_eq_self_of_isClosed {X : C} {S : Sieve X} (hS : J₁.IsClosed S) : J₁.close S = S := (J₁.isClosed_iff_close_eq_self S).1 hS /-- Closing under `J` is stable under pullback. -/ theorem pullback_close {X Y : C} (f : Y ⟶ X) (S : Sieve X) : J₁.close (S.pullback f) = (J₁.close S).pullback f := by apply le_antisymm · refine J₁.le_close_of_isClosed (Sieve.pullback_monotone _ (J₁.le_close S)) ?_ apply J₁.isClosed_pullback _ _ (J₁.close_isClosed _) · intro Z g hg change _ ∈ J₁ _ rw [← Sieve.pullback_comp] apply hg @[mono] theorem monotone_close {X : C} : Monotone (J₁.close : Sieve X → Sieve X) := (J₁.closureOperator _).monotone @[simp] theorem close_close {X : C} (S : Sieve X) : J₁.close (J₁.close S) = J₁.close S := (J₁.closureOperator _).idempotent _ /-- The sieve `S` is in the topology iff its closure is the maximal sieve. This shows that the closure operator determines the topology. -/ theorem close_eq_top_iff_mem {X : C} (S : Sieve X) : J₁.close S = ⊤ ↔ S ∈ J₁ X := by constructor · intro h apply J₁.transitive (J₁.top_mem X) intro Y f hf change J₁.close S f rwa [h] · intro hS rw [eq_top_iff] intro Y f _ apply J₁.pullback_stable _ hS end GrothendieckTopology /-- The presheaf sending each object to the set of `J`-closed sieves on it. This presheaf is a `J`-sheaf (and will turn out to be a subobject classifier for the category of `J`-sheaves). -/ @[simps] def Functor.closedSieves : Cᵒᵖ ⥤ Type max v u where obj X := { S : Sieve X.unop // J₁.IsClosed S } map f S := ⟨S.1.pullback f.unop, J₁.isClosed_pullback f.unop _ S.2⟩ /-- The presheaf of `J`-closed sieves is a `J`-sheaf. The proof of this is adapted from [MM92], Chapter III, Section 7, Lemma 1. -/ theorem classifier_isSheaf : Presieve.IsSheaf J₁ (Functor.closedSieves J₁) := by intro X S hS rw [← Presieve.isSeparatedFor_and_exists_isAmalgamation_iff_isSheafFor] refine ⟨?_, ?_⟩ · rintro x ⟨M, hM⟩ ⟨N, hN⟩ hM₂ hN₂ simp only [Functor.closedSieves_obj] ext Y f dsimp only [Subtype.coe_mk] rw [← J₁.covers_iff_mem_of_isClosed hM, ← J₁.covers_iff_mem_of_isClosed hN] have q : ∀ ⦃Z : C⦄ (g : Z ⟶ X) (_ : S g), M.pullback g = N.pullback g := fun Z g hg => congr_arg Subtype.val ((hM₂ g hg).trans (hN₂ g hg).symm) have MSNS : M ⊓ S = N ⊓ S := by ext Z g rw [Sieve.inter_apply, Sieve.inter_apply] simp only [and_comm] apply and_congr_right intro hg rw [Sieve.mem_iff_pullback_eq_top, Sieve.mem_iff_pullback_eq_top, q g hg] constructor · intro hf rw [J₁.covers_iff] apply J₁.superset_covering (Sieve.pullback_monotone f inf_le_left) rw [← MSNS] apply J₁.arrow_intersect f M S hf (J₁.pullback_stable _ hS) · intro hf rw [J₁.covers_iff] apply J₁.superset_covering (Sieve.pullback_monotone f inf_le_left) rw [MSNS] apply J₁.arrow_intersect f N S hf (J₁.pullback_stable _ hS) · intro x hx rw [Presieve.compatible_iff_sieveCompatible] at hx let M := Sieve.bind S fun Y f hf => (x f hf).1 have : ∀ ⦃Y⦄ (f : Y ⟶ X) (hf : S f), M.pullback f = (x f hf).1 := by intro Y f hf apply le_antisymm · rintro Z u ⟨W, g, f', hf', hg : (x f' hf').1 _, c⟩ rw [Sieve.mem_iff_pullback_eq_top, ← show (x (u ≫ f) _).1 = (x f hf).1.pullback u from congr_arg Subtype.val (hx f u hf)] conv_lhs => congr; congr; rw [← c] -- Porting note: Originally `simp_rw [← c]` rw [show (x (g ≫ f') _).1 = _ from congr_arg Subtype.val (hx f' g hf')] apply Sieve.pullback_eq_top_of_mem _ hg · apply Sieve.le_pullback_bind S fun Y f hf => (x f hf).1 refine ⟨⟨_, J₁.close_isClosed M⟩, ?_⟩ intro Y f hf simp only [Functor.closedSieves_obj] ext1 dsimp rw [← J₁.pullback_close, this _ hf] apply le_antisymm (J₁.le_close_of_isClosed le_rfl (x f hf).2) (J₁.le_close _) /-- If presheaf of `J₁`-closed sieves is a `J₂`-sheaf then `J₁ ≤ J₂`. Note the converse is true by `classifier_isSheaf` and `isSheaf_of_le`. -/ theorem le_topology_of_closedSieves_isSheaf {J₁ J₂ : GrothendieckTopology C} (h : Presieve.IsSheaf J₁ (Functor.closedSieves J₂)) : J₁ ≤ J₂ := by intro X S hS rw [← J₂.close_eq_top_iff_mem] have : J₂.IsClosed (⊤ : Sieve X) := by intro Y f _ trivial suffices (⟨J₂.close S, J₂.close_isClosed S⟩ : Subtype _) = ⟨⊤, this⟩ by rw [Subtype.ext_iff] at this exact this apply (h S hS).isSeparatedFor.ext intro Y f hf simp only [Functor.closedSieves_obj] ext1 dsimp rw [Sieve.pullback_top, ← J₂.pullback_close, S.pullback_eq_top_of_mem hf, J₂.close_eq_top_iff_mem] apply J₂.top_mem /-- If being a sheaf for `J₁` is equivalent to being a sheaf for `J₂`, then `J₁ = J₂`. -/ theorem topology_eq_iff_same_sheaves {J₁ J₂ : GrothendieckTopology C} : J₁ = J₂ ↔ ∀ P : Cᵒᵖ ⥤ Type max v u, Presieve.IsSheaf J₁ P ↔ Presieve.IsSheaf J₂ P := by constructor · rintro rfl intro P rfl · intro h apply le_antisymm · apply le_topology_of_closedSieves_isSheaf rw [h] apply classifier_isSheaf · apply le_topology_of_closedSieves_isSheaf rw [← h] apply classifier_isSheaf /-- A closure (increasing, inflationary and idempotent) operation on sieves that commutes with pullback induces a Grothendieck topology. In fact, such operations are in bijection with Grothendieck topologies. -/ @[simps] def topologyOfClosureOperator (c : ∀ X : C, ClosureOperator (Sieve X)) (hc : ∀ ⦃X Y : C⦄ (f : Y ⟶ X) (S : Sieve X), c _ (S.pullback f) = (c _ S).pullback f) : GrothendieckTopology C where sieves X := { S | c X S = ⊤ } top_mem' X := top_unique ((c X).le_closure _) pullback_stable' X Y S f hS := by rw [Set.mem_setOf_eq] at hS rw [Set.mem_setOf_eq, hc, hS, Sieve.pullback_top] transitive' X S hS R hR := by rw [Set.mem_setOf_eq] at hS rw [Set.mem_setOf_eq, ← (c X).idempotent, eq_top_iff, ← hS] apply (c X).monotone fun Y f hf => _ intro Y f hf rw [Sieve.mem_iff_pullback_eq_top, ← hc] apply hR hf /-- The topology given by the closure operator `J.close` on a Grothendieck topology is the same as `J`. -/ theorem topologyOfClosureOperator_self : (topologyOfClosureOperator J₁.closureOperator fun _ _ => J₁.pullback_close) = J₁ := by ext X S apply GrothendieckTopology.close_eq_top_iff_mem theorem topologyOfClosureOperator_close (c : ∀ X : C, ClosureOperator (Sieve X)) (pb : ∀ ⦃X Y : C⦄ (f : Y ⟶ X) (S : Sieve X), c Y (S.pullback f) = (c X S).pullback f) (X : C) (S : Sieve X) : (topologyOfClosureOperator c pb).close S = c X S := by ext Y f change c _ (Sieve.pullback f S) = ⊤ ↔ c _ S f rw [pb, Sieve.mem_iff_pullback_eq_top] end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Subcanonical.lean
import Mathlib.CategoryTheory.Limits.Preserves.Ulift import Mathlib.CategoryTheory.Sites.Canonical import Mathlib.CategoryTheory.Sites.Whiskering /-! # Subcanonical Grothendieck topologies This file provides some API for the Yoneda embedding into the category of sheaves for a subcanonical Grothendieck topology. -/ universe v' v u namespace CategoryTheory.GrothendieckTopology open Opposite variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) [Subcanonical J] /-- The equivalence between natural transformations from the yoneda embedding (to the sheaf category) and elements of `F.val.obj X`. -/ def yonedaEquiv {X : C} {F : Sheaf J (Type v)} : (J.yoneda.obj X ⟶ F) ≃ F.val.obj (op X) := (fullyFaithfulSheafToPresheaf _ _).homEquiv.trans CategoryTheory.yonedaEquiv theorem yonedaEquiv_apply {X : C} {F : Sheaf J (Type v)} (f : J.yoneda.obj X ⟶ F) : yonedaEquiv J f = f.val.app (op X) (𝟙 X) := rfl @[simp] theorem yonedaEquiv_symm_app_apply {X : C} {F : Sheaf J (Type v)} (x : F.val.obj (op X)) (Y : Cᵒᵖ) (f : Y.unop ⟶ X) : (J.yonedaEquiv.symm x).val.app Y f = F.val.map f.op x := rfl /-- See also `yonedaEquiv_naturality'` for a more general version. -/ lemma yonedaEquiv_naturality {X Y : C} {F : Sheaf J (Type v)} (f : J.yoneda.obj X ⟶ F) (g : Y ⟶ X) : F.val.map g.op (J.yonedaEquiv f) = J.yonedaEquiv (J.yoneda.map g ≫ f) := by simp [yonedaEquiv, CategoryTheory.yonedaEquiv_naturality] rfl /-- Variant of `yonedaEquiv_naturality` with general `g`. This is technically strictly more general than `yonedaEquiv_naturality`, but `yonedaEquiv_naturality` is sometimes preferable because it can avoid the "motive is not type correct" error. -/ lemma yonedaEquiv_naturality' {X Y : Cᵒᵖ} {F : Sheaf J (Type v)} (f : J.yoneda.obj (unop X) ⟶ F) (g : X ⟶ Y) : F.val.map g (J.yonedaEquiv f) = J.yonedaEquiv (J.yoneda.map g.unop ≫ f) := J.yonedaEquiv_naturality _ _ lemma yonedaEquiv_comp {X : C} {F G : Sheaf J (Type v)} (α : J.yoneda.obj X ⟶ F) (β : F ⟶ G) : J.yonedaEquiv (α ≫ β) = β.val.app _ (J.yonedaEquiv α) := rfl lemma yonedaEquiv_yoneda_map {X Y : C} (f : X ⟶ Y) : J.yonedaEquiv (J.yoneda.map f) = f := by rw [yonedaEquiv_apply] simp lemma yonedaEquiv_symm_naturality_left {X X' : C} (f : X' ⟶ X) (F : Sheaf J (Type v)) (x : F.val.obj ⟨X⟩) : J.yoneda.map f ≫ J.yonedaEquiv.symm x = J.yonedaEquiv.symm ((F.val.map f.op) x) := by apply J.yonedaEquiv.injective simp only [yonedaEquiv_comp, yonedaEquiv_symm_app_apply, Equiv.apply_symm_apply] rw [yonedaEquiv_yoneda_map] lemma yonedaEquiv_symm_naturality_right (X : C) {F F' : Sheaf J (Type v)} (f : F ⟶ F') (x : F.val.obj ⟨X⟩) : J.yonedaEquiv.symm x ≫ f = J.yonedaEquiv.symm (f.val.app ⟨X⟩ x) := by apply J.yonedaEquiv.injective simp [yonedaEquiv_comp] /-- See also `map_yonedaEquiv'` for a more general version. -/ lemma map_yonedaEquiv {X Y : C} {F : Sheaf J (Type v)} (f : J.yoneda.obj X ⟶ F) (g : Y ⟶ X) : F.val.map g.op (J.yonedaEquiv f) = f.val.app (op Y) g := by rw [yonedaEquiv_naturality, yonedaEquiv_comp, yonedaEquiv_yoneda_map] /-- Variant of `map_yonedaEquiv` with general `g`. This is technically strictly more general than `map_yonedaEquiv`, but `map_yonedaEquiv` is sometimes preferable because it can avoid the "motive is not type correct" error. -/ lemma map_yonedaEquiv' {X Y : Cᵒᵖ} {F : Sheaf J (Type v)} (f : J.yoneda.obj (unop X) ⟶ F) (g : X ⟶ Y) : F.val.map g (J.yonedaEquiv f) = f.val.app Y g.unop := by rw [yonedaEquiv_naturality', yonedaEquiv_comp, yonedaEquiv_yoneda_map] lemma yonedaEquiv_symm_map {X Y : Cᵒᵖ} (f : X ⟶ Y) {F : Sheaf J (Type v)} (t : F.val.obj X) : J.yonedaEquiv.symm (F.val.map f t) = J.yoneda.map f.unop ≫ J.yonedaEquiv.symm t := by obtain ⟨u, rfl⟩ := J.yonedaEquiv.surjective t rw [yonedaEquiv_naturality', Equiv.symm_apply_apply, Equiv.symm_apply_apply] /-- Two morphisms of sheaves of types `P ⟶ Q` coincide if the precompositions with morphisms `yoneda.obj X ⟶ P` agree. -/ lemma hom_ext_yoneda {P Q : Sheaf J (Type v)} {f g : P ⟶ Q} (h : ∀ (X : C) (p : J.yoneda.obj X ⟶ P), p ≫ f = p ≫ g) : f = g := by ext X x simpa only [yonedaEquiv_comp, Equiv.apply_symm_apply] using congr_arg (J.yonedaEquiv) (h _ (J.yonedaEquiv.symm x)) /-- A version of `yonedaEquiv` for `uliftYoneda`. -/ def uliftYonedaEquiv {X : C} {F : Sheaf J (Type (max v v'))} : ((uliftYoneda.{v'} J).obj X ⟶ F) ≃ F.val.obj (op X) := (fullyFaithfulSheafToPresheaf _ _).homEquiv.trans CategoryTheory.uliftYonedaEquiv @[deprecated (since := "2025-11-10")] alias yonedaULiftEquiv := uliftYonedaEquiv theorem uliftYonedaEquiv_apply {X : C} {F : Sheaf J (Type (max v v'))} (f : J.uliftYoneda.obj X ⟶ F) : uliftYonedaEquiv.{v'} J f = f.val.app (op X) ⟨𝟙 X⟩ := rfl @[deprecated (since := "2025-11-10")] alias yonedaULiftEquiv_apply := uliftYonedaEquiv_apply @[simp] theorem uliftYonedaEquiv_symm_app_apply {X : C} {F : Sheaf J (Type (max v v'))} (x : F.val.obj (op X)) (Y : Cᵒᵖ) (f : Y.unop ⟶ X) : (J.uliftYonedaEquiv.symm x).val.app Y ⟨f⟩ = F.val.map f.op x := rfl @[deprecated (since := "2025-11-10")] alias yonedaULiftEquiv_symm_app_apply := uliftYonedaEquiv_symm_app_apply /-- See also `uliftYonedaEquiv_naturality'` for a more general version. -/ lemma uliftYonedaEquiv_naturality {X Y : C} {F : Sheaf J (Type (max v v'))} (f : J.uliftYoneda.obj X ⟶ F) (g : Y ⟶ X) : F.val.map g.op (J.uliftYonedaEquiv f) = J.uliftYonedaEquiv (J.uliftYoneda.map g ≫ f) := by change (f.val.app (op X) ≫ F.val.map g.op) ⟨𝟙 X⟩ = f.val.app (op Y) ⟨𝟙 Y ≫ g⟩ rw [← f.val.naturality] simp [uliftYoneda] @[deprecated (since := "2025-11-10")] alias yonedaULiftEquiv_naturality := uliftYonedaEquiv_naturality /-- Variant of `uliftYonedaEquiv_naturality` with general `g`. This is technically strictly more general than `uliftYonedaEquiv_naturality`, but `uliftYonedaEquiv_naturality` is sometimes preferable because it can avoid the "motive is not type correct" error. -/ lemma uliftYonedaEquiv_naturality' {X Y : Cᵒᵖ} {F : Sheaf J (Type (max v v'))} (f : J.uliftYoneda.obj (unop X) ⟶ F) (g : X ⟶ Y) : F.val.map g (J.uliftYonedaEquiv f) = J.uliftYonedaEquiv (J.uliftYoneda.map g.unop ≫ f) := J.uliftYonedaEquiv_naturality _ _ @[deprecated (since := "2025-11-10")] alias yonedaULiftEquiv_naturality' := uliftYonedaEquiv_naturality' lemma uliftYonedaEquiv_comp {X : C} {F G : Sheaf J (Type (max v v'))} (α : J.uliftYoneda.obj X ⟶ F) (β : F ⟶ G) : J.uliftYonedaEquiv (α ≫ β) = β.val.app _ (J.uliftYonedaEquiv α) := rfl @[deprecated (since := "2025-11-10")] alias yonedaULiftEquiv_comp := uliftYonedaEquiv_comp lemma uliftYonedaEquiv_uliftYoneda_map {X Y : C} (f : X ⟶ Y) : (uliftYonedaEquiv.{v'} J) (J.uliftYoneda.map f) = ⟨f⟩ := by rw [uliftYonedaEquiv_apply] simp [uliftYoneda] @[deprecated (since := "2025-11-10")] alias yonedaULiftEquiv_yonedaULift_map := uliftYonedaEquiv_uliftYoneda_map lemma uliftYonedaEquiv_symm_naturality_left {X X' : C} (f : X' ⟶ X) (F : Sheaf J (Type (max v v'))) (x : F.val.obj ⟨X⟩) : J.uliftYoneda.map f ≫ J.uliftYonedaEquiv.symm x = J.uliftYonedaEquiv.symm ((F.val.map f.op) x) := by apply J.uliftYonedaEquiv.injective simp only [uliftYonedaEquiv_comp, Equiv.apply_symm_apply] rw [uliftYonedaEquiv_uliftYoneda_map] rfl @[deprecated (since := "2025-11-10")] alias yonedaULiftEquiv_symm_naturality_left := uliftYonedaEquiv_symm_naturality_left lemma uliftYonedaEquiv_symm_naturality_right (X : C) {F F' : Sheaf J (Type (max v v'))} (f : F ⟶ F') (x : F.val.obj ⟨X⟩) : J.uliftYonedaEquiv.symm x ≫ f = J.uliftYonedaEquiv.symm (f.val.app ⟨X⟩ x) := by apply J.uliftYonedaEquiv.injective simp [uliftYonedaEquiv_comp] @[deprecated (since := "2025-11-10")] alias yonedaULiftEquiv_symm_naturality_right := uliftYonedaEquiv_symm_naturality_right /-- See also `map_yonedaEquiv'` for a more general version. -/ lemma map_uliftYonedaEquiv {X Y : C} {F : Sheaf J (Type (max v v'))} (f : J.uliftYoneda.obj X ⟶ F) (g : Y ⟶ X) : F.val.map g.op (J.uliftYonedaEquiv f) = f.val.app (op Y) ⟨g⟩ := by rw [uliftYonedaEquiv_naturality, uliftYonedaEquiv_comp, uliftYonedaEquiv_uliftYoneda_map] @[deprecated (since := "2025-11-10")] alias map_yonedaULiftEquiv := map_uliftYonedaEquiv /-- Variant of `map_uliftYonedaEquiv` with general `g`. This is technically strictly more general than `map_uliftYonedaEquiv`, but `map_uliftYonedaEquiv` is sometimes preferable because it can avoid the "motive is not type correct" error. -/ lemma map_uliftYonedaEquiv' {X Y : Cᵒᵖ} {F : Sheaf J (Type (max v v'))} (f : J.uliftYoneda.obj (unop X) ⟶ F) (g : X ⟶ Y) : F.val.map g (J.uliftYonedaEquiv f) = f.val.app Y ⟨g.unop⟩ := by rw [uliftYonedaEquiv_naturality', uliftYonedaEquiv_comp, uliftYonedaEquiv_uliftYoneda_map] @[deprecated (since := "2025-11-10")] alias map_yonedaULiftEquiv' := map_uliftYonedaEquiv' lemma uliftYonedaEquiv_symm_map {X Y : Cᵒᵖ} (f : X ⟶ Y) {F : Sheaf J (Type (max v v'))} (t : F.val.obj X) : J.uliftYonedaEquiv.symm (F.val.map f t) = J.uliftYoneda.map f.unop ≫ J.uliftYonedaEquiv.symm t := by obtain ⟨u, rfl⟩ := J.uliftYonedaEquiv.surjective t rw [uliftYonedaEquiv_naturality', Equiv.symm_apply_apply, Equiv.symm_apply_apply] @[deprecated (since := "2025-11-10")] alias yonedaULiftEquiv_symm_map := uliftYonedaEquiv_symm_map /-- Two morphisms of sheaves of types `P ⟶ Q` coincide if the precompositions with morphisms `uliftYoneda.obj X ⟶ P` agree. -/ lemma hom_ext_uliftYoneda {P Q : Sheaf J (Type (max v v'))} {f g : P ⟶ Q} (h : ∀ (X : C) (p : J.uliftYoneda.obj X ⟶ P), p ≫ f = p ≫ g) : f = g := by ext X x simpa only [uliftYonedaEquiv_comp, Equiv.apply_symm_apply] using congr_arg (J.uliftYonedaEquiv) (h _ (J.uliftYonedaEquiv.symm x)) @[deprecated (since := "2025-11-10")] alias hom_ext_yonedaULift := hom_ext_uliftYoneda end CategoryTheory.GrothendieckTopology
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/MayerVietorisSquare.lean
import Mathlib.Algebra.Category.Grp.Abelian import Mathlib.Algebra.Category.Grp.Adjunctions import Mathlib.Algebra.Homology.ShortComplex.ShortExact import Mathlib.Algebra.Homology.Square import Mathlib.CategoryTheory.Limits.FunctorCategory.EpiMono import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Square import Mathlib.CategoryTheory.Sites.Abelian import Mathlib.CategoryTheory.Sites.Adjunction import Mathlib.CategoryTheory.Sites.Sheafification /-! # Mayer-Vietoris squares The purpose of this file is to allow the formalization of long exact Mayer-Vietoris sequences in sheaf cohomology. If `X₄` is an open subset of a topological space that is covered by two open subsets `X₂` and `X₃`, it is known that there is a long exact sequence `... ⟶ H^q(X₄) ⟶ H^q(X₂) ⊞ H^q(X₃) ⟶ H^q(X₁) ⟶ H^{q+1}(X₄) ⟶ ...` where `X₁` is the intersection of `X₂` and `X₃`, and `H^q` are the cohomology groups with values in an abelian sheaf. In this file, we introduce a structure `GrothendieckTopology.MayerVietorisSquare` which extends `Square C`, and asserts properties which shall imply the existence of long exact Mayer-Vietoris sequences in sheaf cohomology (TODO). We require that the map `X₁ ⟶ X₃` is a monomorphism and that the square in `C` becomes a pushout square in the category of sheaves after the application of the functor `yoneda ⋙ presheafToSheaf J _`. Note that in the standard case of a covering by two open subsets, all the morphisms in the square would be monomorphisms, but this dissymmetry allows the example of Nisnevich distinguished squares in the case of the Nisnevich topology on schemes (in which case `f₂₄ : X₂ ⟶ X₄` shall be an open immersion and `f₃₄ : X₃ ⟶ X₄` an étale map that is an isomorphism over the closed (reduced) subscheme `X₄ - X₂`, and `X₁` shall be the pullback of `f₂₄` and `f₃₄`.). Given a Mayer-Vietoris square `S` and a presheaf `P` on `C`, we introduce a sheaf condition `S.SheafCondition P` and show that it is indeed satisfied by sheaves. ## References * https://stacks.math.columbia.edu/tag/08GL -/ universe v v' u u' namespace CategoryTheory open Limits Opposite variable {C : Type u} [Category.{v} C] {J : GrothendieckTopology C} lemma Sheaf.isPullback_square_op_map_yoneda_presheafToSheaf_yoneda_iff [HasWeakSheafify J (Type v)] (F : Sheaf J (Type v)) (sq : Square C) : (sq.op.map ((yoneda ⋙ presheafToSheaf J _).op ⋙ yoneda.obj F)).IsPullback ↔ (sq.op.map F.val).IsPullback := by refine Square.IsPullback.iff_of_equiv _ _ (((sheafificationAdjunction J (Type v)).homEquiv _ _).trans yonedaEquiv) (((sheafificationAdjunction J (Type v)).homEquiv _ _).trans yonedaEquiv) (((sheafificationAdjunction J (Type v)).homEquiv _ _).trans yonedaEquiv) (((sheafificationAdjunction J (Type v)).homEquiv _ _).trans yonedaEquiv) ?_ ?_ ?_ ?_ all_goals ext x dsimp rw [yonedaEquiv_naturality] erw [Adjunction.homEquiv_naturality_left] rfl namespace GrothendieckTopology variable (J) /-- A Mayer-Vietoris square in a category `C` equipped with a Grothendieck topology consists of a commutative square `f₁₂ ≫ f₂₄ = f₁₃ ≫ f₃₄` in `C` such that `f₁₃` is a monomorphism and that the square becomes a pushout square in the category of sheaves of sets. -/ structure MayerVietorisSquare [HasWeakSheafify J (Type v)] extends Square C where mono_f₁₃ : Mono toSquare.f₁₃ := by infer_instance /-- the square becomes a pushout square in the category of sheaves of types -/ isPushout : (toSquare.map (yoneda ⋙ presheafToSheaf J _)).IsPushout namespace MayerVietorisSquare attribute [instance] mono_f₁₃ variable {J} section variable [HasWeakSheafify J (Type v)] /-- Constructor for Mayer-Vietoris squares taking as an input a square `sq` such that `sq.f₁₃` is a mono and that for every sheaf of types `F`, the square `sq.op.map F.val` is a pullback square. -/ @[simps toSquare] noncomputable def mk' (sq : Square C) [Mono sq.f₁₃] (H : ∀ (F : Sheaf J (Type v)), (sq.op.map F.val).IsPullback) : J.MayerVietorisSquare where toSquare := sq isPushout := by rw [Square.isPushout_iff_op_map_yoneda_isPullback] intro F exact (F.isPullback_square_op_map_yoneda_presheafToSheaf_yoneda_iff sq).2 (H F) /-- Constructor for Mayer-Vietoris squares taking as an input a pullback square `sq` such that `sq.f₂₄` and `sq.f₃₄` are two monomorphisms which form a covering of `S.X₄`. -/ @[simps! toSquare] noncomputable def mk_of_isPullback (sq : Square C) [Mono sq.f₂₄] [Mono sq.f₃₄] (h₁ : sq.IsPullback) (h₂ : Sieve.ofTwoArrows sq.f₂₄ sq.f₃₄ ∈ J sq.X₄) : J.MayerVietorisSquare := have : Mono sq.f₁₃ := h₁.mono_f₁₃ mk' sq (fun F ↦ by apply Square.IsPullback.mk refine PullbackCone.IsLimit.mk _ (fun s ↦ F.2.amalgamateOfArrows _ h₂ (fun j ↦ WalkingPair.casesOn j s.fst s.snd) (fun W ↦ by rintro (_ | _) (_ | _) a b fac · obtain rfl : a = b := by simpa only [← cancel_mono sq.f₂₄] using fac rfl · obtain ⟨φ, rfl, rfl⟩ := PullbackCone.IsLimit.lift' h₁.isLimit _ _ fac simpa using s.condition =≫ F.val.map φ.op · obtain ⟨φ, rfl, rfl⟩ := PullbackCone.IsLimit.lift' h₁.isLimit _ _ fac.symm simpa using s.condition.symm =≫ F.val.map φ.op · obtain rfl : a = b := by simpa only [← cancel_mono sq.f₃₄] using fac rfl)) (fun _ ↦ ?_) (fun _ ↦ ?_) (fun s m hm₁ hm₂ ↦ ?_) · exact F.2.amalgamateOfArrows_map _ _ _ _ WalkingPair.left · exact F.2.amalgamateOfArrows_map _ _ _ _ WalkingPair.right · apply F.2.hom_ext_ofArrows _ h₂ rintro (_ | _) · rw [F.2.amalgamateOfArrows_map _ _ _ _ WalkingPair.left] exact hm₁ · rw [F.2.amalgamateOfArrows_map _ _ _ _ WalkingPair.right] exact hm₂) variable (S : J.MayerVietorisSquare) lemma isPushoutAddCommGrpFreeSheaf [HasWeakSheafify J AddCommGrpCat.{v}] : (S.map (yoneda ⋙ (Functor.whiskeringRight _ _ _).obj AddCommGrpCat.free ⋙ presheafToSheaf J _)).IsPushout := (S.isPushout.map (Sheaf.composeAndSheafify J AddCommGrpCat.free)).of_iso ((Square.mapFunctor.mapIso (presheafToSheafCompComposeAndSheafifyIso J AddCommGrpCat.free)).app (S.map yoneda)) /-- The condition that a Mayer-Vietoris square becomes a pullback square when we evaluate a presheaf on it. -/ def SheafCondition {A : Type u'} [Category.{v'} A] (P : Cᵒᵖ ⥤ A) : Prop := (S.toSquare.op.map P).IsPullback lemma sheafCondition_iff_comp_coyoneda {A : Type u'} [Category.{v'} A] (P : Cᵒᵖ ⥤ A) : S.SheafCondition P ↔ ∀ (X : Aᵒᵖ), S.SheafCondition (P ⋙ coyoneda.obj X) := Square.isPullback_iff_map_coyoneda_isPullback (S.op.map P) /-- Given a Mayer-Vietoris square `S` and a presheaf of types, this is the map from `P.obj (op S.X₄)` to the explicit fibre product of `P.map S.f₁₂.op` and `P.map S.f₁₃.op`. -/ abbrev toPullbackObj (P : Cᵒᵖ ⥤ Type v') : P.obj (op S.X₄) → Types.PullbackObj (P.map S.f₁₂.op) (P.map S.f₁₃.op) := (S.toSquare.op.map P).pullbackCone.toPullbackObj lemma sheafCondition_iff_bijective_toPullbackObj (P : Cᵒᵖ ⥤ Type v') : S.SheafCondition P ↔ Function.Bijective (S.toPullbackObj P) := by have := (S.toSquare.op.map P).pullbackCone.isLimitEquivBijective exact ⟨fun h ↦ this h.isLimit, fun h ↦ Square.IsPullback.mk _ (this.symm h)⟩ namespace SheafCondition variable {S} variable {P : Cᵒᵖ ⥤ Type v'} (h : S.SheafCondition P) include h lemma bijective_toPullbackObj : Function.Bijective (S.toPullbackObj P) := by rwa [← sheafCondition_iff_bijective_toPullbackObj] lemma ext {x y : P.obj (op S.X₄)} (h₁ : P.map S.f₂₄.op x = P.map S.f₂₄.op y) (h₂ : P.map S.f₃₄.op x = P.map S.f₃₄.op y) : x = y := h.bijective_toPullbackObj.injective (by ext <;> assumption) variable (u : P.obj (op S.X₂)) (v : P.obj (op S.X₃)) (huv : P.map S.f₁₂.op u = P.map S.f₁₃.op v) /-- If `S` is a Mayer-Vietoris square, and `P` is a presheaf which satisfies the sheaf condition with respect to `S`, then elements of `P` over `S.X₂` and `S.X₃` can be glued if the coincide over `S.X₁`. -/ noncomputable def glue : P.obj (op S.X₄) := (PullbackCone.IsLimit.equivPullbackObj h.isLimit).symm ⟨⟨u, v⟩, huv⟩ @[simp] lemma map_f₂₄_op_glue : P.map S.f₂₄.op (h.glue u v huv) = u := PullbackCone.IsLimit.equivPullbackObj_symm_apply_fst h.isLimit _ @[simp] lemma map_f₃₄_op_glue : P.map S.f₃₄.op (h.glue u v huv) = v := PullbackCone.IsLimit.equivPullbackObj_symm_apply_snd h.isLimit _ end SheafCondition lemma sheafCondition_of_sheaf {A : Type u'} [Category.{v} A] (F : Sheaf J A) : S.SheafCondition F.val := by rw [sheafCondition_iff_comp_coyoneda] intro X exact (Sheaf.isPullback_square_op_map_yoneda_presheafToSheaf_yoneda_iff _ S.toSquare).1 (S.isPushout.op.map (yoneda.obj ⟨_, (isSheaf_iff_isSheaf_of_type _ _).2 (F.cond X.unop)⟩)) end variable [HasWeakSheafify J (Type v)] [HasSheafify J AddCommGrpCat.{v}] (S : J.MayerVietorisSquare) /-- The short complex of abelian sheaves `ℤ[S.X₁] ⟶ ℤ[S.X₂] ⊞ ℤ[S.X₃] ⟶ ℤ[S.X₄]` where the left map is a difference and the right map a sum. -/ @[simps] noncomputable def shortComplex : ShortComplex (Sheaf J AddCommGrpCat.{v}) where X₁ := (presheafToSheaf J _).obj (yoneda.obj S.X₁ ⋙ AddCommGrpCat.free) X₂ := (presheafToSheaf J _).obj (yoneda.obj S.X₂ ⋙ AddCommGrpCat.free) ⊞ (presheafToSheaf J _).obj (yoneda.obj S.X₃ ⋙ AddCommGrpCat.free) X₃ := (presheafToSheaf J _).obj (yoneda.obj S.X₄ ⋙ AddCommGrpCat.free) f := biprod.lift ((presheafToSheaf J _).map (Functor.whiskerRight (yoneda.map S.f₁₂) _)) (-(presheafToSheaf J _).map (Functor.whiskerRight (yoneda.map S.f₁₃) _)) g := biprod.desc ((presheafToSheaf J _).map (Functor.whiskerRight (yoneda.map S.f₂₄) _)) ((presheafToSheaf J _).map (Functor.whiskerRight (yoneda.map S.f₃₄) _)) zero := (S.map (yoneda ⋙ (Functor.whiskeringRight _ _ _).obj AddCommGrpCat.free ⋙ presheafToSheaf J _)).cokernelCofork.condition instance : Mono S.shortComplex.f := by have : Mono (S.shortComplex.f ≫ biprod.snd) := by dsimp simp only [biprod.lift_snd] infer_instance exact mono_of_mono _ biprod.snd instance : Epi S.shortComplex.g := (S.shortComplex.exact_and_epi_g_iff_g_is_cokernel.2 ⟨S.isPushoutAddCommGrpFreeSheaf.isColimitCokernelCofork⟩).2 lemma shortComplex_exact : S.shortComplex.Exact := ShortComplex.exact_of_g_is_cokernel _ S.isPushoutAddCommGrpFreeSheaf.isColimitCokernelCofork lemma shortComplex_shortExact : S.shortComplex.ShortExact where exact := S.shortComplex_exact end MayerVietorisSquare end GrothendieckTopology end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Equivalence.lean
import Mathlib.CategoryTheory.Sites.DenseSubsite.InducedTopology import Mathlib.CategoryTheory.Sites.LocallyBijective import Mathlib.CategoryTheory.Sites.PreservesLocallyBijective import Mathlib.CategoryTheory.Sites.Whiskering /-! # Equivalences of sheaf categories Given a site `(C, J)` and a category `D` which is equivalent to `C`, with `C` and `D` possibly large and possibly in different universes, we transport the Grothendieck topology `J` on `C` to `D` and prove that the sheaf categories are equivalent. We also prove that sheafification and the property `HasSheafCompose` transport nicely over this equivalence, and apply it to essentially small sites. We also provide instances for existence of sufficiently small limits in the sheaf category on the essentially small site. ## Main definitions * `CategoryTheory.Equivalence.sheafCongr` is the equivalence of sheaf categories. * `CategoryTheory.Equivalence.transportAndSheafify` is the functor which takes a presheaf on `C`, transports it over the equivalence to `D`, sheafifies there and then transports back to `C`. * `CategoryTheory.Equivalence.transportSheafificationAdjunction`: `transportAndSheafify` is left adjoint to the functor taking a sheaf to its underlying presheaf. * `CategoryTheory.smallSheafify` is the functor which takes a presheaf on an essentially small site `(C, J)`, transports to a small model, sheafifies there and then transports back to `C`. * `CategoryTheory.smallSheafificationAdjunction`: `smallSheafify` is left adjoint to the functor taking a sheaf to its underlying presheaf. -/ universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ w namespace CategoryTheory open Functor Limits GrothendieckTopology variable {C : Type u₁} [Category.{v₁} C] (J : GrothendieckTopology C) variable {D : Type u₂} [Category.{v₂} D] (K : GrothendieckTopology D) (e : C ≌ D) (G : D ⥤ C) variable (A : Type u₃) [Category.{v₃} A] namespace Equivalence instance (priority := 900) [G.IsEquivalence] : IsCoverDense G J where is_cover U := by let e := (asEquivalence G).symm convert J.top_mem U ext Y f simp only [Sieve.top_apply, iff_true] let g : e.inverse.obj _ ⟶ U := (e.unitInv.app Y) ≫ f have : (Sieve.coverByImage e.inverse U).arrows g := Presieve.in_coverByImage _ g replace := Sieve.downward_closed _ this (e.unit.app Y) simpa [g] using this instance : e.functor.IsDenseSubsite J (e.inverse.inducedTopology J) := by have : J = e.functor.inducedTopology (e.inverse.inducedTopology J) := by ext X S rw [show S ∈ (e.functor.inducedTopology (e.inverse.inducedTopology J)) X ↔ _ from (GrothendieckTopology.pullback_mem_iff_of_isIso (i := e.unit.app X)).symm] congr!; ext Y f; simp nth_rw 1 [this] infer_instance lemma eq_inducedTopology_of_isDenseSubsite [e.inverse.IsDenseSubsite K J] : K = e.inverse.inducedTopology J := by ext exact (e.inverse.functorPushforward_mem_iff K J).symm variable [e.inverse.IsDenseSubsite K J] instance : e.functor.IsDenseSubsite J K := by rw [e.eq_inducedTopology_of_isDenseSubsite J K] infer_instance /-- The functor in the equivalence of sheaf categories. -/ @[simps!] def sheafCongr.functor : Sheaf J A ⥤ Sheaf K A where obj F := ⟨e.inverse.op ⋙ F.val, e.inverse.op_comp_isSheaf _ _ _⟩ map f := ⟨whiskerLeft e.inverse.op f.val⟩ /-- The inverse in the equivalence of sheaf categories. -/ @[simps!] def sheafCongr.inverse : Sheaf K A ⥤ Sheaf J A where obj F := ⟨e.functor.op ⋙ F.val, e.functor.op_comp_isSheaf _ _ _⟩ map f := ⟨whiskerLeft e.functor.op f.val⟩ /-- The unit iso in the equivalence of sheaf categories. -/ @[simps!] def sheafCongr.unitIso : 𝟭 (Sheaf J A) ≅ functor J K e A ⋙ inverse J K e A := NatIso.ofComponents (fun F ↦ ⟨⟨(isoWhiskerRight e.op.unitIso F.val).hom⟩, ⟨(isoWhiskerRight e.op.unitIso F.val).inv⟩, Sheaf.hom_ext _ _ (isoWhiskerRight e.op.unitIso F.val).hom_inv_id, Sheaf.hom_ext _ _ (isoWhiskerRight e.op.unitIso F.val).inv_hom_id⟩ ) (by aesop) /-- The counit iso in the equivalence of sheaf categories. -/ @[simps!] def sheafCongr.counitIso : inverse J K e A ⋙ functor J K e A ≅ 𝟭 (Sheaf _ A) := NatIso.ofComponents (fun F ↦ ⟨⟨(isoWhiskerRight e.op.counitIso F.val).hom⟩, ⟨(isoWhiskerRight e.op.counitIso F.val).inv⟩, Sheaf.hom_ext _ _ (isoWhiskerRight e.op.counitIso F.val).hom_inv_id, Sheaf.hom_ext _ _ (isoWhiskerRight e.op.counitIso F.val).inv_hom_id⟩ ) (by aesop) /-- The equivalence of sheaf categories. -/ def sheafCongr : Sheaf J A ≌ Sheaf K A where functor := sheafCongr.functor J K e A inverse := sheafCongr.inverse J K e A unitIso := sheafCongr.unitIso J K e A counitIso := sheafCongr.counitIso J K e A functor_unitIso_comp X := by ext simp only [id_obj, sheafCongr.functor_obj_val_obj, comp_obj, Sheaf.comp_val, NatTrans.comp_app, sheafCongr.inverse_obj_val_obj, Opposite.unop_op, sheafCongr.functor_map_val_app, sheafCongr.unitIso_hom_app_val_app, sheafCongr.counitIso_hom_app_val_app, sheafCongr.functor_obj_val_map, Quiver.Hom.unop_op, Sheaf.id_val, NatTrans.id_app] simp [← Functor.map_comp, ← op_comp] variable [HasSheafify K A] /-- Transport a presheaf to the equivalent category and sheafify there. -/ noncomputable def transportAndSheafify : (Cᵒᵖ ⥤ A) ⥤ Sheaf J A := e.op.congrLeft.functor ⋙ presheafToSheaf _ _ ⋙ (e.sheafCongr J K A).inverse /-- An auxiliary definition for the sheafification adjunction. -/ noncomputable def transportIsoSheafToPresheaf : (e.sheafCongr J K A).functor ⋙ sheafToPresheaf K A ⋙ e.op.congrLeft.inverse ≅ sheafToPresheaf J A := NatIso.ofComponents (fun F ↦ isoWhiskerRight e.op.unitIso.symm F.val) (by intros; ext; simp [Equivalence.sheafCongr]) /-- Transporting and sheafifying is left adjoint to taking the underlying presheaf. -/ noncomputable def transportSheafificationAdjunction : transportAndSheafify J K e A ⊣ sheafToPresheaf J A := ((e.op.congrLeft.toAdjunction.comp (sheafificationAdjunction _ _)).comp (e.sheafCongr J K A).symm.toAdjunction).ofNatIsoRight (transportIsoSheafToPresheaf _ _ _ _) noncomputable instance : PreservesFiniteLimits <| transportAndSheafify J K e A where preservesFiniteLimits _ := comp_preservesLimitsOfShape _ _ include K e in /-- Transport `HasSheafify` along an equivalence of sites. -/ theorem hasSheafify : HasSheafify J A := HasSheafify.mk' J A (transportSheafificationAdjunction J K e A) variable {A : Type*} [Category A] {B : Type*} [Category B] (F : A ⥤ B) [K.HasSheafCompose F] include K e in theorem hasSheafCompose : J.HasSheafCompose F where isSheaf P hP := by have hP' : Presheaf.IsSheaf K (e.inverse.op ⋙ P ⋙ F) := by change Presheaf.IsSheaf K ((_ ⋙ _) ⋙ _) apply HasSheafCompose.isSheaf exact e.inverse.op_comp_isSheaf K J ⟨P, hP⟩ replace hP' : Presheaf.IsSheaf J (e.functor.op ⋙ e.inverse.op ⋙ P ⋙ F) := e.functor.op_comp_isSheaf _ _ ⟨_, hP'⟩ exact (Presheaf.isSheaf_of_iso_iff ((isoWhiskerRight e.op.unitIso.symm (P ⋙ F)))).mp hP' end Equivalence variable (B : Type u₄) [Category.{v₄} B] (F : A ⥤ B) section variable [EssentiallySmall.{w} C] variable [HasSheafify ((equivSmallModel C).inverse.inducedTopology J) A] variable [((equivSmallModel C).inverse.inducedTopology J).HasSheafCompose F] /-- Transport to a small model and sheafify there. -/ noncomputable def smallSheafify : (Cᵒᵖ ⥤ A) ⥤ Sheaf J A := (equivSmallModel C).transportAndSheafify J ((equivSmallModel C).inverse.inducedTopology J) A /-- Transporting to a small model and sheafifying there is left adjoint to the underlying presheaf functor -/ noncomputable def smallSheafificationAdjunction : smallSheafify J A ⊣ sheafToPresheaf J A := (equivSmallModel C).transportSheafificationAdjunction J _ A lemma hasSheafifyEssentiallySmallSite : HasSheafify J A := (equivSmallModel C).hasSheafify J ((equivSmallModel C).inverse.inducedTopology J) A instance hasSheafComposeEssentiallySmallSite : HasSheafCompose J F := (equivSmallModel C).hasSheafCompose J ((equivSmallModel C).inverse.inducedTopology J) F omit [HasSheafify ((equivSmallModel C).inverse.inducedTopology J) A] in lemma hasLimitsEssentiallySmallSite [HasLimits <| Sheaf ((equivSmallModel C).inverse.inducedTopology J) A] : HasLimitsOfSize.{max v₃ w, max v₃ w} <| Sheaf J A := Adjunction.has_limits_of_equivalence ((equivSmallModel C).sheafCongr J ((equivSmallModel C).inverse.inducedTopology J) A).functor instance hasColimitsEssentiallySmallSite [HasColimits <| Sheaf ((equivSmallModel C).inverse.inducedTopology J) A] : HasColimitsOfSize.{max v₃ w, max v₃ w} <| Sheaf J A := Adjunction.has_colimits_of_equivalence ((equivSmallModel C).sheafCongr J ((equivSmallModel C).inverse.inducedTopology J) A).functor end namespace GrothendieckTopology variable {A} variable [G.IsCoverDense J] [G.Full] section variable [Functor.IsContinuous.{v₃} G K J] [(G.sheafPushforwardContinuous A K J).EssSurj] open Localization lemma W_inverseImage_whiskeringLeft : K.W.inverseImage ((whiskeringLeft Dᵒᵖ Cᵒᵖ A).obj G.op) = J.W := by ext P Q f have h₁ : K.W (A := A) = Localization.LeftBousfield.W (· ∈ Set.range (sheafToPresheaf J A ⋙ ((whiskeringLeft Dᵒᵖ Cᵒᵖ A).obj G.op)).obj) := by rw [W_eq_W_range_sheafToPresheaf_obj, ← LeftBousfield.W_isoClosure] conv_rhs => rw [← LeftBousfield.W_isoClosure] apply congr_arg ext P constructor · rintro ⟨_, ⟨R, rfl⟩, ⟨e⟩⟩ exact ⟨_, ⟨_, rfl⟩, ⟨e.trans ((sheafToPresheaf _ _).mapIso ((G.sheafPushforwardContinuous A K J).objObjPreimageIso R).symm)⟩⟩ · rintro ⟨_, ⟨R, rfl⟩, ⟨e⟩⟩ exact ⟨G.op ⋙ R.val, ⟨(G.sheafPushforwardContinuous A K J).obj R, rfl⟩, ⟨e⟩⟩ have h₂ : ∀ (R : Sheaf J A), Function.Bijective (fun (g : G.op ⋙ Q ⟶ G.op ⋙ R.val) ↦ whiskerLeft G.op f ≫ g) ↔ Function.Bijective (fun (g : Q ⟶ R.val) ↦ f ≫ g) := fun R ↦ by rw [← Function.Bijective.of_comp_iff _ (Functor.whiskerLeft_obj_map_bijective_of_isCoverDense J G Q R.val R.cond)] exact Function.Bijective.of_comp_iff' (Functor.whiskerLeft_obj_map_bijective_of_isCoverDense J G P R.val R.cond) (fun g ↦ f ≫ g) rw [h₁, J.W_eq_W_range_sheafToPresheaf_obj, MorphismProperty.inverseImage_iff] constructor · rintro h _ ⟨R, rfl⟩ exact (h₂ R).1 (h _ ⟨R, rfl⟩) · rintro h _ ⟨R, rfl⟩ exact (h₂ R).2 (h _ ⟨R, rfl⟩) lemma W_whiskerLeft_iff {P Q : Cᵒᵖ ⥤ A} (f : P ⟶ Q) : K.W (whiskerLeft G.op f) ↔ J.W f := by rw [← W_inverseImage_whiskeringLeft J K G] rfl end lemma PreservesSheafification.transport [Functor.IsContinuous.{v₄} G K J] [Functor.IsContinuous.{v₃} G K J] [(G.sheafPushforwardContinuous B K J).EssSurj] [(G.sheafPushforwardContinuous A K J).EssSurj] [K.PreservesSheafification F] : J.PreservesSheafification F where le P Q f hf := by rw [← J.W_whiskerLeft_iff (G := G) (K := K)] at hf have := K.W_of_preservesSheafification F (whiskerLeft G.op f) hf rw [whiskerRight_left] at this haveI := K.W.of_postcomp (W' := MorphismProperty.isomorphisms _) _ _ (Iso.isIso_inv _) <| K.W.of_precomp (W' := MorphismProperty.isomorphisms _) _ _ (Iso.isIso_hom _) this rwa [K.W_whiskerLeft_iff (G := G) (J := J) (f := whiskerRight f F)] at this variable [Functor.IsContinuous.{v₃} G K J] [(G.sheafPushforwardContinuous A K J).EssSurj] variable [G.IsCocontinuous K J] {FA : A → A → Type*} {CA : A → Type*} variable [∀ X Y, FunLike (FA X Y) (CA X) (CA Y)] [ConcreteCategory A FA] variable [K.WEqualsLocallyBijective A] lemma WEqualsLocallyBijective.transport (hG : CoverPreserving K J G) : J.WEqualsLocallyBijective A where iff f := by rw [← W_whiskerLeft_iff J K G f, ← Presheaf.isLocallyInjective_whisker_iff K J G f hG, ← Presheaf.isLocallySurjective_whisker_iff K J G f hG, W_iff_isLocallyBijective] variable [EssentiallySmall.{w} C] [∀ (X : Cᵒᵖ), HasLimitsOfShape (StructuredArrow X (equivSmallModel C).inverse.op) A] lemma WEqualsLocallyBijective.ofEssentiallySmall [((equivSmallModel C).inverse.inducedTopology J).WEqualsLocallyBijective A] : J.WEqualsLocallyBijective A := WEqualsLocallyBijective.transport J ((equivSmallModel C).inverse.inducedTopology J) (equivSmallModel C).inverse (IsDenseSubsite.coverPreserving _ _ _) variable [∀ (X : Cᵒᵖ), HasLimitsOfShape (StructuredArrow X (equivSmallModel C).inverse.op) B] variable [PreservesSheafification ((equivSmallModel C).inverse.inducedTopology J) F] instance : PreservesSheafification J F := PreservesSheafification.transport (A := A) J ((equivSmallModel C).inverse.inducedTopology J) (equivSmallModel C).inverse B F end GrothendieckTopology end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/CompatibleSheafification.lean
import Mathlib.CategoryTheory.Sites.CompatiblePlus import Mathlib.CategoryTheory.Sites.ConcreteSheafification /-! In this file, we prove that sheafification is compatible with functors which preserve the correct limits and colimits. -/ namespace CategoryTheory.GrothendieckTopology open CategoryTheory open CategoryTheory.Limits CategoryTheory.Functor open Opposite universe w₁ w₂ v u variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) variable {D : Type w₁} [Category.{max v u} D] variable {E : Type w₂} [Category.{max v u} E] variable (F : D ⥤ E) variable [∀ (J : MulticospanShape.{max v u, max v u}), HasLimitsOfShape (WalkingMulticospan J) D] variable [∀ (J : MulticospanShape.{max v u, max v u}), HasLimitsOfShape (WalkingMulticospan J) E] variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ E] variable [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ F] variable [∀ (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F] variable (P : Cᵒᵖ ⥤ D) /-- The isomorphism between the sheafification of `P` composed with `F` and the sheafification of `P ⋙ F`. Use the lemmas `whisker_right_to_sheafify_sheafify_comp_iso_hom`, `to_sheafify_comp_sheafify_comp_iso_inv` and `sheafify_comp_iso_inv_eq_sheafify_lift` to reduce the components of this isomorphisms to a state that can be handled using the universal property of sheafification. -/ noncomputable def sheafifyCompIso : J.sheafify P ⋙ F ≅ J.sheafify (P ⋙ F) := J.plusCompIso _ _ ≪≫ (J.plusFunctor _).mapIso (J.plusCompIso _ _) /-- The isomorphism between the sheafification of `P` composed with `F` and the sheafification of `P ⋙ F`, functorially in `F`. -/ noncomputable def sheafificationWhiskerLeftIso (P : Cᵒᵖ ⥤ D) [∀ (F : D ⥤ E) (X : C), PreservesColimitsOfShape (J.Cover X)ᵒᵖ F] [∀ (F : D ⥤ E) (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F] : (whiskeringLeft _ _ E).obj (J.sheafify P) ≅ (whiskeringLeft _ _ _).obj P ⋙ J.sheafification E := by refine J.plusFunctorWhiskerLeftIso _ ≪≫ ?_ ≪≫ associator _ _ _ refine isoWhiskerRight ?_ _ exact J.plusFunctorWhiskerLeftIso _ @[simp] theorem sheafificationWhiskerLeftIso_hom_app (P : Cᵒᵖ ⥤ D) (F : D ⥤ E) [∀ (F : D ⥤ E) (X : C), PreservesColimitsOfShape (J.Cover X)ᵒᵖ F] [∀ (F : D ⥤ E) (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F] : (sheafificationWhiskerLeftIso J P).hom.app F = (J.sheafifyCompIso F P).hom := by dsimp [sheafificationWhiskerLeftIso, sheafifyCompIso] rw [Category.comp_id] @[simp] theorem sheafificationWhiskerLeftIso_inv_app (P : Cᵒᵖ ⥤ D) (F : D ⥤ E) [∀ (F : D ⥤ E) (X : C), PreservesColimitsOfShape (J.Cover X)ᵒᵖ F] [∀ (F : D ⥤ E) (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F] : (sheafificationWhiskerLeftIso J P).inv.app F = (J.sheafifyCompIso F P).inv := by dsimp [sheafificationWhiskerLeftIso, sheafifyCompIso] erw [Category.id_comp] /-- The isomorphism between the sheafification of `P` composed with `F` and the sheafification of `P ⋙ F`, functorially in `P`. -/ noncomputable def sheafificationWhiskerRightIso : J.sheafification D ⋙ (whiskeringRight _ _ _).obj F ≅ (whiskeringRight _ _ _).obj F ⋙ J.sheafification E := by refine associator _ _ _ ≪≫ ?_ refine isoWhiskerLeft (J.plusFunctor D) (J.plusFunctorWhiskerRightIso _) ≪≫ ?_ refine ?_ ≪≫ associator _ _ _ refine (associator _ _ _).symm ≪≫ ?_ exact isoWhiskerRight (J.plusFunctorWhiskerRightIso _) (J.plusFunctor E) @[simp] theorem sheafificationWhiskerRightIso_hom_app : (J.sheafificationWhiskerRightIso F).hom.app P = (J.sheafifyCompIso F P).hom := by dsimp [sheafificationWhiskerRightIso, sheafifyCompIso] simp only [Category.id_comp, Category.comp_id] erw [Category.id_comp] @[simp] theorem sheafificationWhiskerRightIso_inv_app : (J.sheafificationWhiskerRightIso F).inv.app P = (J.sheafifyCompIso F P).inv := by dsimp [sheafificationWhiskerRightIso, sheafifyCompIso] simp only [Category.comp_id] erw [Category.id_comp] @[simp, reassoc] theorem whiskerRight_toSheafify_sheafifyCompIso_hom : whiskerRight (J.toSheafify _) _ ≫ (J.sheafifyCompIso F P).hom = J.toSheafify _ := by dsimp [sheafifyCompIso] erw [whiskerRight_comp, Category.assoc] slice_lhs 2 3 => rw [plusCompIso_whiskerRight] rw [Category.assoc, ← J.plusMap_comp, whiskerRight_toPlus_comp_plusCompIso_hom, ← Category.assoc, whiskerRight_toPlus_comp_plusCompIso_hom] rfl @[simp, reassoc] theorem toSheafify_comp_sheafifyCompIso_inv : J.toSheafify _ ≫ (J.sheafifyCompIso F P).inv = whiskerRight (J.toSheafify _) _ := by rw [Iso.comp_inv_eq]; simp section -- We will sheafify `D`-valued presheaves in this section. variable {FD : D → D → Type*} {CD : D → Type (max v u)} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] variable [ConcreteCategory.{max v u} D FD] [PreservesLimits (forget D)] [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ (forget D)] [(forget D).ReflectsIsomorphisms] @[simp] theorem sheafifyCompIso_inv_eq_sheafifyLift : (J.sheafifyCompIso F P).inv = J.sheafifyLift (whiskerRight (J.toSheafify P) F) (HasSheafCompose.isSheaf _ ((J.sheafify_isSheaf _))) := by apply J.sheafifyLift_unique rw [Iso.comp_inv_eq] simp end end CategoryTheory.GrothendieckTopology
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/ConcreteSheafification.lean
import Mathlib.CategoryTheory.Sites.Plus import Mathlib.CategoryTheory.Limits.Shapes.ConcreteCategory /-! # Sheafification We construct the sheafification of a presheaf over a site `C` with values in `D` whenever `D` is a concrete category for which the forgetful functor preserves the appropriate (co)limits and reflects isomorphisms. We generally follow the approach of https://stacks.math.columbia.edu/tag/00W1 -/ namespace CategoryTheory open CategoryTheory.Limits Opposite universe t w' w v u variable {C : Type u} [Category.{v} C] {J : GrothendieckTopology C} variable {D : Type w} [Category.{w'} D] section variable {FD : D → D → Type*} {CD : D → Type t} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] variable [ConcreteCategory.{t} D FD] /-- A concrete version of the multiequalizer, to be used below. -/ def Meq {X : C} (P : Cᵒᵖ ⥤ D) (S : J.Cover X) := { x : ∀ I : S.Arrow, ToType (P.obj (op I.Y)) // ∀ I : S.Relation, P.map I.r.g₁.op (x I.fst) = P.map I.r.g₂.op (x I.snd) } end namespace Meq variable {FD : D → D → Type*} {CD : D → Type t} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] variable [ConcreteCategory.{t} D FD] instance {X} (P : Cᵒᵖ ⥤ D) (S : J.Cover X) : CoeFun (Meq P S) fun _ => ∀ I : S.Arrow, ToType (P.obj (op I.Y)) := ⟨fun x => x.1⟩ lemma congr_apply {X} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x : Meq P S) {Y} {f g : Y ⟶ X} (h : f = g) (hf : S f) : x ⟨_, _, hf⟩ = x ⟨_, g, by simpa only [← h] using hf⟩ := by subst h rfl @[ext] theorem ext {X} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x y : Meq P S) (h : ∀ I : S.Arrow, x I = y I) : x = y := Subtype.ext <| funext <| h theorem condition {X} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x : Meq P S) (I : S.Relation) : P.map I.r.g₁.op (x (S.shape.fst I)) = P.map I.r.g₂.op (x (S.shape.snd I)) := x.2 _ /-- Refine a term of `Meq P T` with respect to a refinement `S ⟶ T` of covers. -/ def refine {X : C} {P : Cᵒᵖ ⥤ D} {S T : J.Cover X} (x : Meq P T) (e : S ⟶ T) : Meq P S := ⟨fun I => x ⟨I.Y, I.f, (leOfHom e) _ I.hf⟩, fun I => x.condition (GrothendieckTopology.Cover.Relation.mk' (I.r.map e))⟩ @[simp] theorem refine_apply {X : C} {P : Cᵒᵖ ⥤ D} {S T : J.Cover X} (x : Meq P T) (e : S ⟶ T) (I : S.Arrow) : x.refine e I = x ⟨I.Y, I.f, (leOfHom e) _ I.hf⟩ := rfl /-- Pull back a term of `Meq P S` with respect to a morphism `f : Y ⟶ X` in `C`. -/ def pullback {Y X : C} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x : Meq P S) (f : Y ⟶ X) : Meq P ((J.pullback f).obj S) := ⟨fun I => x ⟨_, I.f ≫ f, I.hf⟩, fun I => x.condition (GrothendieckTopology.Cover.Relation.mk' I.r.base)⟩ @[simp] theorem pullback_apply {Y X : C} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x : Meq P S) (f : Y ⟶ X) (I : ((J.pullback f).obj S).Arrow) : x.pullback f I = x ⟨_, I.f ≫ f, I.hf⟩ := rfl @[simp] theorem pullback_refine {Y X : C} {P : Cᵒᵖ ⥤ D} {S T : J.Cover X} (h : S ⟶ T) (f : Y ⟶ X) (x : Meq P T) : (x.pullback f).refine ((J.pullback f).map h) = (refine x h).pullback _ := rfl /-- Make a term of `Meq P S`. -/ def mk {X : C} {P : Cᵒᵖ ⥤ D} (S : J.Cover X) (x : ToType (P.obj (op X))) : Meq P S := ⟨fun I => P.map I.f.op x, fun I => by simp only [← ConcreteCategory.comp_apply, ← P.map_comp, ← op_comp, I.r.w]⟩ theorem mk_apply {X : C} {P : Cᵒᵖ ⥤ D} (S : J.Cover X) (x : ToType (P.obj (op X))) (I : S.Arrow) : mk S x I = P.map I.f.op x := rfl variable [∀ {X : C} (S : J.Cover X), PreservesLimitsOfShape (WalkingMulticospan S.shape) (forget D)] /-- The equivalence between the type associated to `multiequalizer (S.index P)` and `Meq P S`. -/ noncomputable def equiv {X : C} (P : Cᵒᵖ ⥤ D) (S : J.Cover X) [HasMultiequalizer (S.index P)] : ToType (multiequalizer (S.index P)) ≃ Meq P S := Limits.Concrete.multiequalizerEquiv.{t} (C := D) _ @[simp] theorem equiv_apply {X : C} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} [HasMultiequalizer (S.index P)] (x : ToType (multiequalizer (S.index P))) (I : S.Arrow) : equiv P S x I = Multiequalizer.ι (S.index P) I x := rfl theorem equiv_symm_eq_apply {X : C} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} [HasMultiequalizer (S.index P)] (x : Meq P S) (I : S.Arrow) : -- We can hint `ConcreteCategory.hom (Y := P.obj (op I.Y))` below to put it into `simp`-normal -- form, but that doesn't seem to fix the `erw`s below... (Multiequalizer.ι (S.index P) I) ((Meq.equiv P S).symm x) = x I := by simp [← GrothendieckTopology.Cover.index_left, ← equiv_apply] end Meq namespace GrothendieckTopology namespace Plus variable {FD : D → D → Type*} {CD : D → Type t} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] variable [instCC : ConcreteCategory.{t} D FD] variable [∀ {X : C} (S : J.Cover X), PreservesLimitsOfShape (WalkingMulticospan S.shape) (forget D)] variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] variable [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.Cover X), HasMultiequalizer (S.index P)] noncomputable section /-- Make a term of `(J.plusObj P).obj (op X)` from `x : Meq P S`. -/ def mk {X : C} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x : Meq P S) : ToType ((J.plusObj P).obj (op X)) := colimit.ι (J.diagram P X) (op S) ((Meq.equiv P S).symm x) theorem res_mk_eq_mk_pullback {Y X : C} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x : Meq P S) (f : Y ⟶ X) : (J.plusObj P).map f.op (mk x) = mk (x.pullback f) := by dsimp [mk, plusObj] rw [← comp_apply (x := (Meq.equiv P S).symm x), ι_colimMap_assoc, colimit.ι_pre, comp_apply (x := (Meq.equiv P S).symm x)] apply congr_arg apply (Meq.equiv P _).injective dsimp only [Functor.op_obj, pullback_obj] rw [Equiv.apply_symm_apply] ext i simp only [Functor.op_obj, unop_op, pullback_obj, diagram_obj, Functor.comp_obj, diagramPullback_app, Meq.equiv_apply, Meq.pullback_apply] rw [← ConcreteCategory.comp_apply, Multiequalizer.lift_ι] erw [Meq.equiv_symm_eq_apply] cases i; rfl theorem toPlus_mk {X : C} {P : Cᵒᵖ ⥤ D} (S : J.Cover X) (x : ToType (P.obj (op X))) : (J.toPlus P).app _ x = mk (Meq.mk S x) := by dsimp [mk, toPlus] let e : S ⟶ ⊤ := homOfLE (OrderTop.le_top _) rw [← colimit.w _ e.op] delta Cover.toMultiequalizer rw [ConcreteCategory.comp_apply, ConcreteCategory.comp_apply] apply congr_arg dsimp [diagram] apply Concrete.multiequalizer_ext (C := D) intro i simp only [← ConcreteCategory.comp_apply, Category.assoc, Multiequalizer.lift_ι, Meq.equiv_symm_eq_apply] rfl theorem toPlus_apply {X : C} {P : Cᵒᵖ ⥤ D} (S : J.Cover X) (x : Meq P S) (I : S.Arrow) : (J.toPlus P).app _ (x I) = (J.plusObj P).map I.f.op (mk x) := by dsimp only [toPlus, plusObj] delta Cover.toMultiequalizer dsimp [mk] rw [← ConcreteCategory.comp_apply, ι_colimMap_assoc, colimit.ι_pre, ConcreteCategory.comp_apply, ConcreteCategory.comp_apply] dsimp only [Functor.op] let e : (J.pullback I.f).obj (unop (op S)) ⟶ ⊤ := homOfLE (OrderTop.le_top _) rw [← colimit.w _ e.op, ConcreteCategory.comp_apply] apply congr_arg apply Concrete.multiequalizer_ext (C := D) intro i dsimp rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply, Multiequalizer.lift_ι, Multiequalizer.lift_ι, Multiequalizer.lift_ι] erw [Meq.equiv_symm_eq_apply] simpa using (x.condition (Cover.Relation.mk' (I.precompRelation i.f))).symm theorem toPlus_eq_mk {X : C} {P : Cᵒᵖ ⥤ D} (x : ToType (P.obj (op X))) : (J.toPlus P).app _ x = mk (Meq.mk ⊤ x) := toPlus_mk ⊤ x variable [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ (forget D)] theorem exists_rep {X : C} {P : Cᵒᵖ ⥤ D} (x : ToType ((J.plusObj P).obj (op X))) : ∃ (S : J.Cover X) (y : Meq P S), x = mk y := by obtain ⟨S, y, h⟩ := Concrete.colimit_exists_rep (J.diagram P X) x use S.unop, Meq.equiv _ _ y rw [← h] dsimp [mk] simp theorem eq_mk_iff_exists {X : C} {P : Cᵒᵖ ⥤ D} {S T : J.Cover X} (x : Meq P S) (y : Meq P T) : mk x = mk y ↔ ∃ (W : J.Cover X) (h1 : W ⟶ S) (h2 : W ⟶ T), x.refine h1 = y.refine h2 := by constructor · intro h obtain ⟨W, h1, h2, hh⟩ := Concrete.colimit_exists_of_rep_eq (C := D) _ _ _ h use W.unop, h1.unop, h2.unop ext I apply_fun Multiequalizer.ι (W.unop.index P) I at hh convert hh all_goals dsimp [diagram] rw [← ConcreteCategory.comp_apply, Multiequalizer.lift_ι] erw [Meq.equiv_symm_eq_apply] cases I; rfl · rintro ⟨S, h1, h2, e⟩ apply Concrete.colimit_rep_eq_of_exists (C := D) use op S, h1.op, h2.op apply Concrete.multiequalizer_ext intro i apply_fun fun ee => ee i at e convert e using 1 all_goals dsimp [diagram] rw [← ConcreteCategory.comp_apply, Multiequalizer.lift_ι] erw [Meq.equiv_symm_eq_apply] cases i; rfl /-- `P⁺` is always separated. -/ theorem sep {X : C} (P : Cᵒᵖ ⥤ D) (S : J.Cover X) (x y : ToType ((J.plusObj P).obj (op X))) (h : ∀ I : S.Arrow, (J.plusObj P).map I.f.op x = (J.plusObj P).map I.f.op y) : x = y := by -- First, we choose representatives for x and y. obtain ⟨Sx, x, rfl⟩ := exists_rep x obtain ⟨Sy, y, rfl⟩ := exists_rep y simp only [res_mk_eq_mk_pullback] at h -- Next, using our assumption, -- choose covers over which the pullbacks of these representatives become equal. choose W h1 h2 hh using fun I : S.Arrow => (eq_mk_iff_exists _ _).mp (h I) -- To prove equality, it suffices to prove that there exists a cover over which -- the representatives become equal. rw [eq_mk_iff_exists] -- Construct the cover over which the representatives become equal by combining the various -- covers chosen above. let B : J.Cover X := S.bind W use B -- Prove that this cover refines the two covers over which our representatives are defined -- and use these proofs. let ex : B ⟶ Sx := homOfLE (by rintro Y f ⟨Z, e1, e2, he2, he1, hee⟩ rw [← hee] apply leOfHom (h1 ⟨_, _, he2⟩) exact he1) let ey : B ⟶ Sy := homOfLE (by rintro Y f ⟨Z, e1, e2, he2, he1, hee⟩ rw [← hee] apply leOfHom (h2 ⟨_, _, he2⟩) exact he1) use ex, ey -- Now prove that indeed the representatives become equal over `B`. -- This will follow by using the fact that our representatives become -- equal over the chosen covers. ext1 I let IS : S.Arrow := I.fromMiddle specialize hh IS let IW : (W IS).Arrow := I.toMiddle apply_fun fun e => e IW at hh convert hh using 1 · exact x.congr_apply I.middle_spec.symm _ · exact y.congr_apply I.middle_spec.symm _ theorem inj_of_sep (P : Cᵒᵖ ⥤ D) (hsep : ∀ (X : C) (S : J.Cover X) (x y : ToType (P.obj (op X))), (∀ I : S.Arrow, P.map I.f.op x = P.map I.f.op y) → x = y) (X : C) : Function.Injective ((J.toPlus P).app (op X)) := by intro x y h simp only [toPlus_eq_mk] at h rw [eq_mk_iff_exists] at h obtain ⟨W, h1, h2, hh⟩ := h apply hsep X W intro I apply_fun fun e => e I at hh exact hh /-- An auxiliary definition to be used in the proof of `exists_of_sep` below. Given a compatible family of local sections for `P⁺`, and representatives of said sections, construct a compatible family of local sections of `P` over the combination of the covers associated to the representatives. The separatedness condition is used to prove compatibility among these local sections of `P`. -/ def meqOfSep (P : Cᵒᵖ ⥤ D) (hsep : ∀ (X : C) (S : J.Cover X) (x y : ToType (P.obj (op X))), (∀ I : S.Arrow, P.map I.f.op x = P.map I.f.op y) → x = y) (X : C) (S : J.Cover X) (s : Meq (J.plusObj P) S) (T : ∀ I : S.Arrow, J.Cover I.Y) (t : ∀ I : S.Arrow, Meq P (T I)) (ht : ∀ I : S.Arrow, s I = mk (t I)) : Meq P (S.bind T) where val I := t I.fromMiddle I.toMiddle property := by intro II apply inj_of_sep P hsep rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply, (J.toPlus P).naturality, (J.toPlus P).naturality, ConcreteCategory.comp_apply, ConcreteCategory.comp_apply] erw [toPlus_apply (T II.fst.fromMiddle) (t II.fst.fromMiddle) II.fst.toMiddle, toPlus_apply (T II.snd.fromMiddle) (t II.snd.fromMiddle) II.snd.toMiddle] rw [← ht, ← ht] erw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply]; rw [← (J.plusObj P).map_comp, ← (J.plusObj P).map_comp, ← op_comp, ← op_comp] exact s.condition { fst.hf := II.fst.from_middle_condition snd.hf := II.snd.from_middle_condition r.g₁ := II.r.g₁ ≫ II.fst.toMiddleHom r.g₂ := II.r.g₂ ≫ II.snd.toMiddleHom r.w := by simpa only [Category.assoc, Cover.Arrow.middle_spec] using II.r.w .. } theorem exists_of_sep (P : Cᵒᵖ ⥤ D) (hsep : ∀ (X : C) (S : J.Cover X) (x y : ToType (P.obj (op X))), (∀ I : S.Arrow, P.map I.f.op x = P.map I.f.op y) → x = y) (X : C) (S : J.Cover X) (s : Meq (J.plusObj P) S) : ∃ t : ToType ((J.plusObj P).obj (op X)), Meq.mk S t = s := by have inj : ∀ X : C, Function.Injective ((J.toPlus P).app (op X)) := inj_of_sep _ hsep -- Choose representatives for the given local sections. choose T t ht using fun I => exists_rep (s I) -- Construct a large cover over which we will define a representative that will -- provide the gluing of the given local sections. let B : J.Cover X := S.bind T choose Z e1 e2 he2 _ _ using fun I : B.Arrow => I.hf -- Construct a compatible system of local sections over this large cover, using the chosen -- representatives of our local sections. -- The compatibility here follows from the separatedness assumption. let w : Meq P B := meqOfSep P hsep X S s T t ht -- The associated gluing will be the candidate section. use mk w ext I dsimp [Meq.mk] rw [ht, res_mk_eq_mk_pullback] -- Use the separatedness of `P⁺` to prove that this is indeed a gluing of our -- original local sections. apply sep P (T I) intro II simp only [res_mk_eq_mk_pullback, eq_mk_iff_exists] -- It suffices to prove equality for representatives over a -- convenient sufficiently large cover... use (J.pullback II.f).obj (T I) let e0 : (J.pullback II.f).obj (T I) ⟶ (J.pullback II.f).obj ((J.pullback I.f).obj B) := homOfLE (by intro Y f hf apply Sieve.le_pullback_bind _ _ _ I.hf · cases I exact hf) use e0, 𝟙 _ ext IV let IA : B.Arrow := ⟨_, (IV.f ≫ II.f) ≫ I.f, ⟨I.Y, _, _, I.hf, Sieve.downward_closed _ II.hf _, rfl⟩⟩ let IB : S.Arrow := IA.fromMiddle let IC : (T IB).Arrow := IA.toMiddle let ID : (T I).Arrow := ⟨IV.Y, IV.f ≫ II.f, Sieve.downward_closed (T I).1 II.hf IV.f⟩ change t IB IC = t I ID apply inj IV.Y rw [toPlus_apply (T I) (t I) ID] erw [toPlus_apply (T IB) (t IB) IC] rw [← ht, ← ht] -- Conclude by constructing the relation showing equality... let IR : S.Relation := { fst.hf := IB.hf, snd.hf := I.hf, r.w := IA.middle_spec, .. } exact s.condition IR variable [(forget D).ReflectsIsomorphisms] /-- If `P` is separated, then `P⁺` is a sheaf. -/ theorem isSheaf_of_sep (P : Cᵒᵖ ⥤ D) (hsep : ∀ (X : C) (S : J.Cover X) (x y : ToType (P.obj (op X))), (∀ I : S.Arrow, P.map I.f.op x = P.map I.f.op y) → x = y) : Presheaf.IsSheaf J (J.plusObj P) := by rw [Presheaf.isSheaf_iff_multiequalizer] intro X S apply @isIso_of_reflects_iso _ _ _ _ _ _ _ (forget D) ?_ rw [isIso_iff_bijective] constructor · intro x y h apply sep P S _ _ intro I apply_fun Meq.equiv _ _ at h apply_fun fun e => e I at h dsimp only [ConcreteCategory.forget_map_eq_coe] at h convert h <;> erw [Meq.equiv_apply] <;> rw [← ConcreteCategory.comp_apply, Multiequalizer.lift_ι] <;> rfl · rintro (x : ToType (multiequalizer (S.index _))) obtain ⟨t, ht⟩ := exists_of_sep P hsep X S (Meq.equiv _ _ x) use t apply (Meq.equiv (D := D) _ _).injective rw [← ht] ext i dsimp rw [← ConcreteCategory.comp_apply, Multiequalizer.lift_ι] rfl variable (J) include instCC /-- `P⁺⁺` is always a sheaf. -/ theorem isSheaf_plus_plus (P : Cᵒᵖ ⥤ D) : Presheaf.IsSheaf J (J.plusObj (J.plusObj P)) := by apply isSheaf_of_sep intro X S x y apply sep end end Plus variable (J) variable [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.Cover X), HasMultiequalizer (S.index P)] [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] /-- The sheafification of a presheaf `P`. *NOTE:* Additional hypotheses are needed to obtain a proof that this is a sheaf! -/ noncomputable def sheafify (P : Cᵒᵖ ⥤ D) : Cᵒᵖ ⥤ D := J.plusObj (J.plusObj P) /-- The canonical map from `P` to its sheafification. -/ noncomputable def toSheafify (P : Cᵒᵖ ⥤ D) : P ⟶ J.sheafify P := J.toPlus P ≫ J.plusMap (J.toPlus P) /-- The canonical map on sheafifications induced by a morphism. -/ noncomputable def sheafifyMap {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : J.sheafify P ⟶ J.sheafify Q := J.plusMap <| J.plusMap η @[simp] theorem sheafifyMap_id (P : Cᵒᵖ ⥤ D) : J.sheafifyMap (𝟙 P) = 𝟙 (J.sheafify P) := by dsimp [sheafifyMap, sheafify] simp @[simp] theorem sheafifyMap_comp {P Q R : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (γ : Q ⟶ R) : J.sheafifyMap (η ≫ γ) = J.sheafifyMap η ≫ J.sheafifyMap γ := by dsimp [sheafifyMap, sheafify] simp @[reassoc (attr := simp)] theorem toSheafify_naturality {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : η ≫ J.toSheafify _ = J.toSheafify _ ≫ J.sheafifyMap η := by dsimp [sheafifyMap, sheafify, toSheafify] simp variable (D) /-- The sheafification of a presheaf `P`, as a functor. *NOTE:* Additional hypotheses are needed to obtain a proof that this is a sheaf! -/ noncomputable def sheafification : (Cᵒᵖ ⥤ D) ⥤ Cᵒᵖ ⥤ D := J.plusFunctor D ⋙ J.plusFunctor D @[simp] theorem sheafification_obj (P : Cᵒᵖ ⥤ D) : (J.sheafification D).obj P = J.sheafify P := rfl @[simp] theorem sheafification_map {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : (J.sheafification D).map η = J.sheafifyMap η := rfl /-- The canonical map from `P` to its sheafification, as a natural transformation. *Note:* We only show this is a sheaf under additional hypotheses on `D`. -/ noncomputable def toSheafification : 𝟭 _ ⟶ sheafification J D := J.toPlusNatTrans D ≫ Functor.whiskerRight (J.toPlusNatTrans D) (J.plusFunctor D) @[simp] theorem toSheafification_app (P : Cᵒᵖ ⥤ D) : (J.toSheafification D).app P = J.toSheafify P := rfl variable {D} theorem isIso_toSheafify {P : Cᵒᵖ ⥤ D} (hP : Presheaf.IsSheaf J P) : IsIso (J.toSheafify P) := by dsimp [toSheafify] haveI := isIso_toPlus_of_isSheaf J P hP change (IsIso (toPlus J P ≫ (J.plusFunctor D).map (toPlus J P))) infer_instance /-- If `P` is a sheaf, then `P` is isomorphic to `J.sheafify P`. -/ noncomputable def isoSheafify {P : Cᵒᵖ ⥤ D} (hP : Presheaf.IsSheaf J P) : P ≅ J.sheafify P := letI := isIso_toSheafify J hP asIso (J.toSheafify P) @[simp] theorem isoSheafify_hom {P : Cᵒᵖ ⥤ D} (hP : Presheaf.IsSheaf J P) : (J.isoSheafify hP).hom = J.toSheafify P := rfl /-- Given a sheaf `Q` and a morphism `P ⟶ Q`, construct a morphism from `J.sheafify P` to `Q`. -/ noncomputable def sheafifyLift {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (hQ : Presheaf.IsSheaf J Q) : J.sheafify P ⟶ Q := J.plusLift (J.plusLift η hQ) hQ @[reassoc (attr := simp)] theorem toSheafify_sheafifyLift {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (hQ : Presheaf.IsSheaf J Q) : J.toSheafify P ≫ sheafifyLift J η hQ = η := by dsimp only [sheafifyLift, toSheafify] simp theorem sheafifyLift_unique {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (hQ : Presheaf.IsSheaf J Q) (γ : J.sheafify P ⟶ Q) : J.toSheafify P ≫ γ = η → γ = sheafifyLift J η hQ := by intro h apply plusLift_unique apply plusLift_unique rw [← Category.assoc, ← plusMap_toPlus] exact h @[simp] theorem isoSheafify_inv {P : Cᵒᵖ ⥤ D} (hP : Presheaf.IsSheaf J P) : (J.isoSheafify hP).inv = J.sheafifyLift (𝟙 _) hP := by apply J.sheafifyLift_unique simp [Iso.comp_inv_eq] theorem sheafify_hom_ext {P Q : Cᵒᵖ ⥤ D} (η γ : J.sheafify P ⟶ Q) (hQ : Presheaf.IsSheaf J Q) (h : J.toSheafify P ≫ η = J.toSheafify P ≫ γ) : η = γ := by apply J.plus_hom_ext _ _ hQ apply J.plus_hom_ext _ _ hQ rw [← Category.assoc, ← Category.assoc, ← plusMap_toPlus] exact h @[reassoc (attr := simp)] theorem sheafifyMap_sheafifyLift {P Q R : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (γ : Q ⟶ R) (hR : Presheaf.IsSheaf J R) : J.sheafifyMap η ≫ J.sheafifyLift γ hR = J.sheafifyLift (η ≫ γ) hR := by apply J.sheafifyLift_unique rw [← Category.assoc, ← J.toSheafify_naturality, Category.assoc, toSheafify_sheafifyLift] end GrothendieckTopology variable (J) variable {FD : D → D → Type*} {CD : D → Type t} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] variable [instCC : ConcreteCategory.{t} D FD] [∀ {X : C} (S : J.Cover X), PreservesLimitsOfShape (WalkingMulticospan S.shape) (forget D)] [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.Cover X), HasMultiequalizer (S.index P)] [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ (forget D)] [(forget D).ReflectsIsomorphisms] include instCC in theorem GrothendieckTopology.sheafify_isSheaf (P : Cᵒᵖ ⥤ D) : Presheaf.IsSheaf J (J.sheafify P) := GrothendieckTopology.Plus.isSheaf_plus_plus _ _ variable (D) /-- The sheafification functor, as a functor taking values in `Sheaf`. -/ @[simps] noncomputable def plusPlusSheaf : (Cᵒᵖ ⥤ D) ⥤ Sheaf J D where obj P := ⟨J.sheafify P, J.sheafify_isSheaf P⟩ map η := ⟨J.sheafifyMap η⟩ map_id _ := Sheaf.Hom.ext <| J.sheafifyMap_id _ map_comp _ _ := Sheaf.Hom.ext <| J.sheafifyMap_comp _ _ instance plusPlusSheaf_preservesZeroMorphisms [Preadditive D] : (plusPlusSheaf J D).PreservesZeroMorphisms where map_zero F G := by ext : 3 refine colimit.hom_ext (fun j => ?_) erw [colimit.ι_map, comp_zero] simp /-- The sheafification functor is left adjoint to the forgetful functor. -/ @[simps! unit_app counit_app_val] noncomputable def plusPlusAdjunction : plusPlusSheaf J D ⊣ sheafToPresheaf J D := Adjunction.mkOfHomEquiv { homEquiv := fun P Q => { toFun := fun e => J.toSheafify P ≫ e.val invFun := fun e => ⟨J.sheafifyLift e Q.2⟩ left_inv := fun _ => Sheaf.Hom.ext <| (J.sheafifyLift_unique _ _ _ rfl).symm right_inv := fun _ => J.toSheafify_sheafifyLift _ _ } homEquiv_naturality_left_symm := by intro P Q R η γ; ext1; dsimp; symm apply J.sheafifyMap_sheafifyLift homEquiv_naturality_right := fun η γ => by dsimp rw [Category.assoc] } instance sheafToPresheaf_isRightAdjoint : (sheafToPresheaf J D).IsRightAdjoint := (plusPlusAdjunction J D).isRightAdjoint instance presheaf_mono_of_mono {F G : Sheaf J D} (f : F ⟶ G) [Mono f] : Mono f.1 := (sheafToPresheaf J D).map_mono _ include instCC in theorem Sheaf.Hom.mono_iff_presheaf_mono {F G : Sheaf J D} (f : F ⟶ G) : Mono f ↔ Mono f.1 := ⟨fun m => by infer_instance, fun m => by exact Sheaf.Hom.mono_of_presheaf_mono J D f⟩ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/LocallySurjective.lean
import Mathlib.CategoryTheory.Sites.Coherent.ExtensiveTopology import Mathlib.CategoryTheory.Sites.Coherent.SheafComparison import Mathlib.CategoryTheory.Sites.LocallySurjective /-! # Locally surjective morphisms of coherent sheaves This file characterises locally surjective morphisms of presheaves for the coherent, regular and extensive topologies. ## Main results * `regularTopology.isLocallySurjective_iff` A morphism of presheaves `f : F ⟶ G` is locally surjective for the regular topology iff for every object `X` of `C`, and every `y : G(X)`, there is an effective epimorphism `φ : X' ⟶ X` and an `x : F(X)` such that `f_{X'}(x) = G(φ)(y)`. * `coherentTopology.isLocallySurjective_iff` a morphism of sheaves for the coherent topology on a preregular finitary extensive category is locally surjective if and only if it is locally surjective for the regular topology. * `extensiveTopology.isLocallySurjective_iff` a morphism of sheaves for the extensive topology on a finitary extensive category is locally surjective iff it is objectwise surjective. -/ universe w open CategoryTheory Sheaf Limits Opposite namespace CategoryTheory variable {C : Type*} (D : Type*) [Category C] [Category D] {FD : D → D → Type*} {CD : D → Type w} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{w} D FD] lemma regularTopology.isLocallySurjective_iff [Preregular C] {F G : Cᵒᵖ ⥤ D} (f : F ⟶ G) : Presheaf.IsLocallySurjective (regularTopology C) f ↔ ∀ (X : C) (y : ToType (G.obj ⟨X⟩)), (∃ (X' : C) (φ : X' ⟶ X) (_ : EffectiveEpi φ) (x : ToType (F.obj ⟨X'⟩)), f.app ⟨X'⟩ x = G.map ⟨φ⟩ y) := by constructor · intro ⟨h⟩ X y specialize h y rw [regularTopology.mem_sieves_iff_hasEffectiveEpi] at h obtain ⟨X', π, h, h'⟩ := h exact ⟨X', π, h, h'⟩ · intro h refine ⟨fun y ↦ ?_⟩ obtain ⟨X', π, h, h'⟩ := h _ y rw [regularTopology.mem_sieves_iff_hasEffectiveEpi] exact ⟨X', π, h, h'⟩ attribute [local instance] Types.instFunLike Types.instConcreteCategory in lemma extensiveTopology.surjective_of_isLocallySurjective_sheaf_of_types [FinitaryPreExtensive C] {F G : Cᵒᵖ ⥤ Type w} (f : F ⟶ G) [PreservesFiniteProducts F] [PreservesFiniteProducts G] (h : Presheaf.IsLocallySurjective (extensiveTopology C) f) {X : C} : Function.Surjective (f.app (op X)) := by intro x replace h := h.1 x rw [mem_sieves_iff_contains_colimit_cofan] at h obtain ⟨α, _, Y, π, h, h'⟩ := h let y : (a : α) → (F.obj ⟨Y a⟩) := fun a ↦ (h' a).choose let _ : Fintype α := Fintype.ofFinite _ let ht := (Types.productLimitCone (fun a ↦ F.obj ⟨Y a⟩)).isLimit let ht' := (Functor.Initial.isLimitWhiskerEquiv (Discrete.opposite α).inverse (Cocone.op (Cofan.mk X π))).symm h.some.op let i : ((a : α) → (F.obj ⟨Y a⟩)) ≅ (F.obj ⟨X⟩) := ht.conePointsIsoOfNatIso (isLimitOfPreserves F ht') (Discrete.natIso (fun _ ↦ (Iso.refl (F.obj ⟨_⟩)))) refine ⟨i.hom y, ?_⟩ apply Concrete.isLimit_ext _ (isLimitOfPreserves G ht') intro ⟨a⟩ simp only [Functor.comp_obj, Discrete.opposite_inverse_obj, Functor.op_obj, Discrete.functor_obj, Functor.mapCone_pt, Cone.whisker_pt, Cocone.op_pt, Cofan.mk_pt, Functor.const_obj_obj, Functor.mapCone_π_app, Cone.whisker_π, Cocone.op_π, Functor.whiskerLeft_app, NatTrans.op_app, Cofan.mk_ι_app] rw [← (h' a).choose_spec] erw [← NatTrans.naturality_apply (φ := f)] change f.app _ ((i.hom ≫ F.map (π a).op) y) = _ erw [IsLimit.map_π] rfl lemma extensiveTopology.presheafIsLocallySurjective_iff [FinitaryPreExtensive C] {F G : Cᵒᵖ ⥤ D} (f : F ⟶ G) [PreservesFiniteProducts F] [PreservesFiniteProducts G] [PreservesFiniteProducts (forget D)] : Presheaf.IsLocallySurjective (extensiveTopology C) f ↔ ∀ (X : C), Function.Surjective (f.app (op X)) := by constructor · rw [Presheaf.isLocallySurjective_iff_whisker_forget (J := extensiveTopology C)] exact fun h _ ↦ surjective_of_isLocallySurjective_sheaf_of_types (Functor.whiskerRight f (forget D)) h · intro h refine ⟨fun {X} y ↦ ?_⟩ obtain ⟨x, hx⟩ := h X y convert (extensiveTopology C).top_mem' X rw [← Sieve.id_mem_iff_eq_top] simpa [Presheaf.imageSieve] using ⟨x, hx⟩ lemma extensiveTopology.isLocallySurjective_iff [FinitaryExtensive C] {F G : Sheaf (extensiveTopology C) D} (f : F ⟶ G) [PreservesFiniteProducts (forget D)] : IsLocallySurjective f ↔ ∀ (X : C), Function.Surjective (f.val.app (op X)) := extensiveTopology.presheafIsLocallySurjective_iff _ f.val attribute [local instance] Types.instFunLike Types.instConcreteCategory in lemma regularTopology.isLocallySurjective_sheaf_of_types [Preregular C] [FinitaryPreExtensive C] {F G : Cᵒᵖ ⥤ Type w} (f : F ⟶ G) [PreservesFiniteProducts F] [PreservesFiniteProducts G] (h : Presheaf.IsLocallySurjective (coherentTopology C) f) : Presheaf.IsLocallySurjective (regularTopology C) f where imageSieve_mem y := by replace h := h.1 y rw [coherentTopology.mem_sieves_iff_hasEffectiveEpiFamily] at h obtain ⟨α, _, Z, π, h, h'⟩ := h rw [mem_sieves_iff_hasEffectiveEpi] let x : (a : α) → (F.obj ⟨Z a⟩) := fun a ↦ (h' a).choose let _ : Fintype α := Fintype.ofFinite _ let i' : ((a : α) → (F.obj ⟨Z a⟩)) ≅ (F.obj ⟨∐ Z⟩) := (Types.productIso _).symm ≪≫ (PreservesProduct.iso F _).symm ≪≫ F.mapIso (opCoproductIsoProduct _).symm refine ⟨∐ Z, Sigma.desc π, inferInstance, i'.hom x, ?_⟩ have := preservesLimitsOfShape_of_equiv (Discrete.opposite α).symm G apply Concrete.isLimit_ext _ (isLimitOfPreserves G (coproductIsCoproduct Z).op) intro ⟨⟨a⟩⟩ simp only [Functor.comp_obj, Functor.op_obj, Discrete.functor_obj, Functor.mapCone_pt, Cocone.op_pt, Cofan.mk_pt, Functor.const_obj_obj, Functor.mapCone_π_app, Cocone.op_π, NatTrans.op_app, Cofan.mk_ι_app, Functor.mapIso_symm, Iso.symm_hom, Iso.trans_hom, Functor.mapIso_inv, types_comp_apply, i', ← NatTrans.naturality_apply f (Sigma.ι Z a).op] have : f.app ⟨Z a⟩ (x a) = G.map (π a).op y := (h' a).choose_spec convert this · change F.map _ (F.map _ _) = _ rw [← FunctorToTypes.map_comp_apply, opCoproductIsoProduct_inv_comp_ι, ← piComparison_comp_π] change ((PreservesProduct.iso F _).hom ≫ _) _ = _ have := Types.productIso_hom_comp_eval (fun a ↦ F.obj (op (Z a))) a rw [← Iso.eq_inv_comp] at this simp only [types_comp_apply, inv_hom_id_apply, congrFun this x] · change G.map _ (G.map _ _) = _ simp only [← FunctorToTypes.map_comp_apply, ← op_comp, Sigma.ι_desc] lemma coherentTopology.presheafIsLocallySurjective_iff {F G : Cᵒᵖ ⥤ D} (f : F ⟶ G) [Preregular C] [FinitaryPreExtensive C] [PreservesFiniteProducts F] [PreservesFiniteProducts G] [PreservesFiniteProducts (forget D)] : Presheaf.IsLocallySurjective (coherentTopology C) f ↔ Presheaf.IsLocallySurjective (regularTopology C) f := by constructor · rw [Presheaf.isLocallySurjective_iff_whisker_forget, Presheaf.isLocallySurjective_iff_whisker_forget (J := regularTopology C)] exact regularTopology.isLocallySurjective_sheaf_of_types _ · refine Presheaf.isLocallySurjective_of_le (J := regularTopology C) ?_ _ rw [← extensive_regular_generate_coherent] exact (Coverage.gi _).gc.monotone_l le_sup_right lemma coherentTopology.isLocallySurjective_iff [Preregular C] [FinitaryExtensive C] {F G : Sheaf (coherentTopology C) D} (f : F ⟶ G) [PreservesFiniteProducts (forget D)] : IsLocallySurjective f ↔ Presheaf.IsLocallySurjective (regularTopology C) f.val := presheafIsLocallySurjective_iff _ f.val end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/SheafComparison.lean
import Mathlib.CategoryTheory.Sites.Coherent.Comparison import Mathlib.CategoryTheory.Sites.Coherent.ExtensiveSheaves import Mathlib.CategoryTheory.Sites.Coherent.ReflectsPrecoherent import Mathlib.CategoryTheory.Sites.Coherent.ReflectsPreregular import Mathlib.CategoryTheory.Sites.DenseSubsite.InducedTopology import Mathlib.CategoryTheory.Sites.Whiskering /-! # Categories of coherent sheaves Given a fully faithful functor `F : C ⥤ D` into a precoherent category, which preserves and reflects finite effective epi families, and satisfies the property `F.EffectivelyEnough` (meaning that to every object in `C` there is an effective epi from an object in the image of `F`), the categories of coherent sheaves on `C` and `D` are equivalent (see `CategoryTheory.coherentTopology.equivalence`). The main application of this equivalence is the characterisation of condensed sets as coherent sheaves on either `CompHaus`, `Profinite` or `Stonean`. See the file `Condensed/Equivalence.lean` We give the corresponding result for the regular topology as well (see `CategoryTheory.regularTopology.equivalence`). -/ universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ namespace CategoryTheory open Limits Functor regularTopology variable {C D : Type*} [Category C] [Category D] (F : C ⥤ D) namespace coherentTopology variable [F.PreservesFiniteEffectiveEpiFamilies] [F.ReflectsFiniteEffectiveEpiFamilies] [F.Full] [F.Faithful] [F.EffectivelyEnough] [Precoherent D] instance : F.IsCoverDense (coherentTopology _) := by refine F.isCoverDense_of_generate_singleton_functor_π_mem _ fun B ↦ ⟨_, F.effectiveEpiOver B, ?_⟩ apply Coverage.Saturate.of refine ⟨Unit, inferInstance, fun _ => F.effectiveEpiOverObj B, fun _ => F.effectiveEpiOver B, ?_, ?_⟩ · funext; ext -- Do we want `Presieve.ext`? refine ⟨fun ⟨⟩ ↦ ⟨()⟩, ?_⟩ rintro ⟨⟩ simp · rw [← effectiveEpi_iff_effectiveEpiFamily] infer_instance theorem exists_effectiveEpiFamily_iff_mem_induced (X : C) (S : Sieve X) : (∃ (α : Type) (_ : Finite α) (Y : α → C) (π : (a : α) → (Y a ⟶ X)), EffectiveEpiFamily Y π ∧ (∀ a : α, (S.arrows) (π a)) ) ↔ (S ∈ F.inducedTopology (coherentTopology _) X) := by refine ⟨fun ⟨α, _, Y, π, ⟨H₁, H₂⟩⟩ ↦ ?_, fun hS ↦ ?_⟩ · apply (mem_sieves_iff_hasEffectiveEpiFamily (Sieve.functorPushforward _ S)).mpr refine ⟨α, inferInstance, fun i => F.obj (Y i), fun i => F.map (π i), ⟨?_, fun a => Sieve.image_mem_functorPushforward F S (H₂ a)⟩⟩ exact F.map_finite_effectiveEpiFamily _ _ · obtain ⟨α, _, Y, π, ⟨H₁, H₂⟩⟩ := (mem_sieves_iff_hasEffectiveEpiFamily _).mp hS refine ⟨α, inferInstance, ?_⟩ let Z : α → C := fun a ↦ (Functor.EffectivelyEnough.presentation (F := F) (Y a)).some.p let g₀ : (a : α) → F.obj (Z a) ⟶ Y a := fun a ↦ F.effectiveEpiOver (Y a) have : EffectiveEpiFamily _ (fun a ↦ g₀ a ≫ π a) := inferInstance refine ⟨Z, fun a ↦ F.preimage (g₀ a ≫ π a), ?_, fun a ↦ (?_ : S.arrows (F.preimage _))⟩ · refine F.finite_effectiveEpiFamily_of_map _ _ ?_ simpa using this · obtain ⟨W, g₁, g₂, h₁, h₂⟩ := H₂ a rw [h₂] convert S.downward_closed h₁ (F.preimage (g₀ a ≫ g₂)) exact F.map_injective (by simp) lemma eq_induced : haveI := F.reflects_precoherent coherentTopology C = F.inducedTopology (coherentTopology _) := by ext X S have := F.reflects_precoherent rw [← exists_effectiveEpiFamily_iff_mem_induced F X] rw [← coherentTopology.mem_sieves_iff_hasEffectiveEpiFamily S] instance : haveI := F.reflects_precoherent; F.IsDenseSubsite (coherentTopology C) (coherentTopology D) where functorPushforward_mem_iff := by rw [eq_induced F] rfl lemma coverPreserving : haveI := F.reflects_precoherent CoverPreserving (coherentTopology _) (coherentTopology _) F := IsDenseSubsite.coverPreserving _ _ _ section SheafEquiv variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] (F : C ⥤ D) [F.PreservesFiniteEffectiveEpiFamilies] [F.ReflectsFiniteEffectiveEpiFamilies] [F.Full] [F.Faithful] [Precoherent D] [F.EffectivelyEnough] /-- The equivalence from coherent sheaves on `C` to coherent sheaves on `D`, given a fully faithful functor `F : C ⥤ D` to a precoherent category, which preserves and reflects effective epimorphic families, and satisfies `F.EffectivelyEnough`. -/ noncomputable def equivalence (A : Type u₃) [Category.{v₃} A] [∀ X, HasLimitsOfShape (StructuredArrow X F.op) A] : haveI := F.reflects_precoherent Sheaf (coherentTopology C) A ≌ Sheaf (coherentTopology D) A := Functor.IsDenseSubsite.sheafEquiv F _ _ _ end SheafEquiv section RegularExtensive variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] (F : C ⥤ D) [F.PreservesEffectiveEpis] [F.ReflectsEffectiveEpis] [F.Full] [F.Faithful] [FinitaryExtensive D] [Preregular D] [FinitaryPreExtensive C] [PreservesFiniteCoproducts F] [F.EffectivelyEnough] /-- The equivalence from coherent sheaves on `C` to coherent sheaves on `D`, given a fully faithful functor `F : C ⥤ D` to an extensive preregular category, which preserves and reflects effective epimorphisms and satisfies `F.EffectivelyEnough`. -/ noncomputable def equivalence' (A : Type u₃) [Category.{v₃} A] [∀ X, HasLimitsOfShape (StructuredArrow X F.op) A] : haveI := F.reflects_precoherent Sheaf (coherentTopology C) A ≌ Sheaf (coherentTopology D) A := Functor.IsDenseSubsite.sheafEquiv F _ _ _ end RegularExtensive end coherentTopology namespace regularTopology variable [F.PreservesEffectiveEpis] [F.ReflectsEffectiveEpis] [F.Full] [F.Faithful] [F.EffectivelyEnough] [Preregular D] instance : F.IsCoverDense (regularTopology _) := by refine F.isCoverDense_of_generate_singleton_functor_π_mem _ fun B ↦ ⟨_, F.effectiveEpiOver B, ?_⟩ apply Coverage.Saturate.of refine ⟨F.effectiveEpiOverObj B, F.effectiveEpiOver B, ?_, inferInstance⟩ funext; ext -- Do we want `Presieve.ext`? refine ⟨fun ⟨⟩ ↦ ⟨()⟩, ?_⟩ rintro ⟨⟩ simp theorem exists_effectiveEpi_iff_mem_induced (X : C) (S : Sieve X) : (∃ (Y : C) (π : Y ⟶ X), EffectiveEpi π ∧ S.arrows π) ↔ (S ∈ F.inducedTopology (regularTopology _) X) := by refine ⟨fun ⟨Y, π, ⟨H₁, H₂⟩⟩ ↦ ?_, fun hS ↦ ?_⟩ · apply (mem_sieves_iff_hasEffectiveEpi (Sieve.functorPushforward _ S)).mpr refine ⟨F.obj Y, F.map π, ⟨?_, Sieve.image_mem_functorPushforward F S H₂⟩⟩ exact F.map_effectiveEpi _ · obtain ⟨Y, π, ⟨H₁, H₂⟩⟩ := (mem_sieves_iff_hasEffectiveEpi _).mp hS let g₀ := F.effectiveEpiOver Y refine ⟨_, F.preimage (g₀ ≫ π), ?_, (?_ : S.arrows (F.preimage _))⟩ · refine F.effectiveEpi_of_map _ ?_ simp only [map_preimage] infer_instance · obtain ⟨W, g₁, g₂, h₁, h₂⟩ := H₂ rw [h₂] convert S.downward_closed h₁ (F.preimage (g₀ ≫ g₂)) exact F.map_injective (by simp) lemma eq_induced : haveI := F.reflects_preregular regularTopology C = F.inducedTopology (regularTopology _) := by ext X S have := F.reflects_preregular rw [← exists_effectiveEpi_iff_mem_induced F X] rw [← mem_sieves_iff_hasEffectiveEpi S] instance : haveI := F.reflects_preregular; F.IsDenseSubsite (regularTopology C) (regularTopology D) where functorPushforward_mem_iff := by rw [eq_induced F] rfl lemma coverPreserving : haveI := F.reflects_preregular CoverPreserving (regularTopology _) (regularTopology _) F := IsDenseSubsite.coverPreserving _ _ _ section SheafEquiv variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] (F : C ⥤ D) [F.PreservesEffectiveEpis] [F.ReflectsEffectiveEpis] [F.Full] [F.Faithful] [Preregular D] [F.EffectivelyEnough] /-- The equivalence from regular sheaves on `C` to regular sheaves on `D`, given a fully faithful functor `F : C ⥤ D` to a preregular category, which preserves and reflects effective epimorphisms and satisfies `F.EffectivelyEnough`. -/ noncomputable def equivalence (A : Type u₃) [Category.{v₃} A] [∀ X, HasLimitsOfShape (StructuredArrow X F.op) A] : haveI := F.reflects_preregular Sheaf (regularTopology C) A ≌ Sheaf (regularTopology D) A := Functor.IsDenseSubsite.sheafEquiv F _ _ _ end SheafEquiv end regularTopology namespace Presheaf variable {A : Type u₃} [Category.{v₃} A] (F : Cᵒᵖ ⥤ A) theorem isSheaf_coherent_iff_regular_and_extensive [Preregular C] [FinitaryPreExtensive C] : IsSheaf (coherentTopology C) F ↔ IsSheaf (extensiveTopology C) F ∧ IsSheaf (regularTopology C) F := by rw [← extensive_regular_generate_coherent] exact isSheaf_sup (extensiveCoverage C) (regularCoverage C) F theorem isSheaf_iff_preservesFiniteProducts_and_equalizerCondition [Preregular C] [FinitaryExtensive C] [h : ∀ {Y X : C} (f : Y ⟶ X) [EffectiveEpi f], HasPullback f f] : IsSheaf (coherentTopology C) F ↔ PreservesFiniteProducts F ∧ EqualizerCondition F := by rw [isSheaf_coherent_iff_regular_and_extensive] exact and_congr (isSheaf_iff_preservesFiniteProducts _) (@equalizerCondition_iff_isSheaf _ _ _ _ F _ h).symm noncomputable instance [Preregular C] [FinitaryExtensive C] (F : Sheaf (coherentTopology C) A) : PreservesFiniteProducts F.val := (Presheaf.isSheaf_iff_preservesFiniteProducts F.val).1 ((Presheaf.isSheaf_coherent_iff_regular_and_extensive F.val).mp F.cond).1 theorem isSheaf_iff_preservesFiniteProducts_of_projective [Preregular C] [FinitaryExtensive C] [∀ (X : C), Projective X] : IsSheaf (coherentTopology C) F ↔ PreservesFiniteProducts F := by rw [isSheaf_coherent_iff_regular_and_extensive, and_iff_left (isSheaf_of_projective F), isSheaf_iff_preservesFiniteProducts] theorem isSheaf_iff_extensiveSheaf_of_projective [Preregular C] [FinitaryExtensive C] [∀ (X : C), Projective X] : IsSheaf (coherentTopology C) F ↔ IsSheaf (extensiveTopology C) F := by rw [isSheaf_iff_preservesFiniteProducts_of_projective, isSheaf_iff_preservesFiniteProducts] /-- The categories of coherent sheaves and extensive sheaves on `C` are equivalent if `C` is preregular, finitary extensive, and every object is projective. -/ @[simps] def coherentExtensiveEquivalence [Preregular C] [FinitaryExtensive C] [∀ (X : C), Projective X] : Sheaf (coherentTopology C) A ≌ Sheaf (extensiveTopology C) A where functor := { obj := fun F ↦ ⟨F.val, (isSheaf_iff_extensiveSheaf_of_projective F.val).mp F.cond⟩ map := fun f ↦ ⟨f.val⟩ } inverse := { obj := fun F ↦ ⟨F.val, (isSheaf_iff_extensiveSheaf_of_projective F.val).mpr F.cond⟩ map := fun f ↦ ⟨f.val⟩ } unitIso := Iso.refl _ counitIso := Iso.refl _ variable {B : Type u₄} [Category.{v₄} B] variable (s : A ⥤ B) lemma isSheaf_coherent_of_hasPullbacks_comp [Preregular C] [FinitaryExtensive C] [h : ∀ {Y X : C} (f : Y ⟶ X) [EffectiveEpi f], HasPullback f f] [PreservesFiniteLimits s] (hF : IsSheaf (coherentTopology C) F) : IsSheaf (coherentTopology C) (F ⋙ s) := by rw [isSheaf_iff_preservesFiniteProducts_and_equalizerCondition (h := h)] at hF ⊢ have := hF.1 refine ⟨inferInstance, fun _ _ π _ c hc ↦ ⟨?_⟩⟩ exact isLimitForkMapOfIsLimit s _ (hF.2 π c hc).some lemma isSheaf_coherent_of_hasPullbacks_of_comp [Preregular C] [FinitaryExtensive C] [h : ∀ {Y X : C} (f : Y ⟶ X) [EffectiveEpi f], HasPullback f f] [ReflectsFiniteLimits s] (hF : IsSheaf (coherentTopology C) (F ⋙ s)) : IsSheaf (coherentTopology C) F := by rw [isSheaf_iff_preservesFiniteProducts_and_equalizerCondition (h := h)] at hF ⊢ obtain ⟨_, hF₂⟩ := hF refine ⟨⟨fun n ↦ ⟨fun {K} ↦ ⟨fun {c} hc ↦ ?_⟩⟩⟩, fun _ _ π _ c hc ↦ ⟨?_⟩⟩ · exact ⟨isLimitOfReflects s (isLimitOfPreserves (F ⋙ s) hc)⟩ · exact isLimitOfIsLimitForkMap s _ (hF₂ π c hc).some lemma isSheaf_coherent_of_projective_comp [Preregular C] [FinitaryExtensive C] [∀ (X : C), Projective X] [PreservesFiniteProducts s] (hF : IsSheaf (coherentTopology C) F) : IsSheaf (coherentTopology C) (F ⋙ s) := by rw [isSheaf_iff_preservesFiniteProducts_of_projective] at hF ⊢ infer_instance lemma isSheaf_coherent_of_projective_of_comp [Preregular C] [FinitaryExtensive C] [∀ (X : C), Projective X] [ReflectsFiniteProducts s] (hF : IsSheaf (coherentTopology C) (F ⋙ s)) : IsSheaf (coherentTopology C) F := by rw [isSheaf_iff_preservesFiniteProducts_of_projective] at hF ⊢ exact ⟨fun n ↦ ⟨fun {K} ↦ ⟨fun {c} hc ↦ ⟨isLimitOfReflects s (isLimitOfPreserves (F ⋙ s) hc)⟩⟩⟩⟩ instance [Preregular C] [FinitaryExtensive C] [h : ∀ {Y X : C} (f : Y ⟶ X) [EffectiveEpi f], HasPullback f f] [PreservesFiniteLimits s] : (coherentTopology C).HasSheafCompose s where isSheaf F hF := isSheaf_coherent_of_hasPullbacks_comp (h := h) F s hF instance [Preregular C] [FinitaryExtensive C] [∀ (X : C), Projective X] [PreservesFiniteProducts s] : (coherentTopology C).HasSheafCompose s where isSheaf F hF := isSheaf_coherent_of_projective_comp F s hF end CategoryTheory.Presheaf
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/ExtensiveColimits.lean
import Mathlib.CategoryTheory.Preadditive.Biproducts import Mathlib.CategoryTheory.Sites.Coherent.ExtensiveSheaves import Mathlib.CategoryTheory.Sites.Limits /-! # Colimits in categories of extensive sheaves This file proves that `J`-shaped colimits of `A`-valued sheaves for the extensive topology are computed objectwise if `colim : J ⥤ A ⥤ A` preserves finite products. This holds for all shapes `J` if `A` is a preadditive category. This can also easily be applied to filtered `J` in the case when `A` is a category of sets, and eventually to sifted `J` once that API is developed. -/ namespace CategoryTheory open Limits Sheaf GrothendieckTopology Opposite section variable {A C J : Type*} [Category A] [Category C] [Category J] [FinitaryExtensive C] [HasColimitsOfShape J A] lemma isSheaf_pointwiseColimit [PreservesFiniteProducts (colim (J := J) (C := A))] (G : J ⥤ Sheaf (extensiveTopology C) A) : Presheaf.IsSheaf (extensiveTopology C) (pointwiseCocone (G ⋙ sheafToPresheaf _ A)).pt := by rw [Presheaf.isSheaf_iff_preservesFiniteProducts] dsimp only [pointwiseCocone_pt] apply (config := { allowSynthFailures := true } ) comp_preservesFiniteProducts have : ∀ (i : J), PreservesFiniteProducts ((G ⋙ sheafToPresheaf _ A).obj i) := fun i ↦ by rw [← Presheaf.isSheaf_iff_preservesFiniteProducts] exact Sheaf.cond _ exact ⟨fun _ ↦ preservesLimitsOfShape_of_evaluation _ _ fun d ↦ inferInstanceAs (PreservesLimitsOfShape _ ((G ⋙ sheafToPresheaf _ _).obj d))⟩ instance [Preadditive A] : PreservesFiniteProducts (colim (J := J) (C := A)) where preserves _ := by apply (config := { allowSynthFailures := true }) preservesProductsOfShape_of_preservesBiproductsOfShape apply preservesBiproductsOfShape_of_preservesCoproductsOfShape instance [PreservesFiniteProducts (colim (J := J) (C := A))] : PreservesColimitsOfShape J (sheafToPresheaf (extensiveTopology C) A) where preservesColimit {G} := by suffices CreatesColimit G (sheafToPresheaf (extensiveTopology C) A) from inferInstance refine createsColimitOfIsSheaf _ (fun c hc ↦ ?_) let i : c.pt ≅ (G ⋙ sheafToPresheaf _ _).flip ⋙ colim := hc.coconePointUniqueUpToIso (pointwiseIsColimit _) rw [Presheaf.isSheaf_of_iso_iff i] exact isSheaf_pointwiseColimit _ instance [Preadditive A] [HasFiniteColimits A] : PreservesFiniteColimits (sheafToPresheaf (extensiveTopology C) A) where preservesFiniteColimits _ := inferInstance end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/SequentialLimit.lean
import Mathlib.CategoryTheory.Functor.OfSequence import Mathlib.CategoryTheory.Sites.Coherent.LocallySurjective import Mathlib.CategoryTheory.Sites.EpiMono import Mathlib.CategoryTheory.Sites.Subcanonical /-! # Limits of epimorphisms in coherent topoi This file proves that a sequential limit of epimorphisms is epimorphic in the category of sheaves for the coherent topology on a preregular finitary extensive category where sequential limits of effective epimorphisms are effective epimorphisms. In other words, given epimorphisms of sheaves `⋯ ⟶ Xₙ₊₁ ⟶ Xₙ ⟶ ⋯ ⟶ X₀`, the projection map `lim Xₙ ⟶ X₀` is an epimorphism (see `coherentTopology.epi_π_app_zero_of_epi`). This is deduced from the corresponding statement about locally surjective morphisms of sheaves (see `coherentTopology.isLocallySurjective_π_app_zero_of_isLocallySurjective_map`). -/ universe w v u open CategoryTheory Limits Opposite namespace CategoryTheory.coherentTopology variable {C : Type u} [Category.{v} C] [Preregular C] [FinitaryExtensive C] attribute [local instance] Types.instFunLike Types.instConcreteCategory variable {F : ℕᵒᵖ ⥤ Sheaf (coherentTopology C) (Type v)} {c : Cone F} (hc : IsLimit c) (hF : ∀ n, Sheaf.IsLocallySurjective (F.map (homOfLE (Nat.le_succ n)).op)) private structure struct (F : ℕᵒᵖ ⥤ Sheaf (coherentTopology C) (Type v)) where X (n : ℕ) : C x (n : ℕ) : (F.obj ⟨n⟩).val.obj ⟨X n⟩ map (n : ℕ) : X (n + 1) ⟶ X n effectiveEpi (n : ℕ) : EffectiveEpi (map n) w (n : ℕ) : (F.map (homOfLE (n.le_add_right 1)).op).val.app (op (X (n + 1))) (x (n + 1)) = (F.obj (op n)).val.map (map n).op (x n) include hF in private lemma exists_effectiveEpi (n : ℕ) (X : C) (y : (F.obj ⟨n⟩).val.obj ⟨X⟩) : ∃ (X' : C) (φ : X' ⟶ X) (_ : EffectiveEpi φ) (x : (F.obj ⟨n + 1⟩).val.obj ⟨X'⟩), ((F.map (homOfLE (n.le_add_right 1)).op).val.app ⟨X'⟩) x = ((F.obj ⟨n⟩).val.map φ.op) y := by have := hF n rw [coherentTopology.isLocallySurjective_iff, regularTopology.isLocallySurjective_iff] at this exact this X y private noncomputable def preimage (X : C) (y : (F.obj ⟨0⟩).val.obj ⟨X⟩) : (n : ℕ) → ((Y : C) × (F.obj ⟨n⟩).val.obj ⟨Y⟩) | 0 => ⟨X, y⟩ | (n + 1) => ⟨(exists_effectiveEpi hF n (preimage X y n).1 (preimage X y n).2).choose, (exists_effectiveEpi hF n (preimage X y n).1 (preimage X y n).2).choose_spec.choose_spec.choose_spec.choose⟩ private noncomputable def preimageStruct (X : C) (y : (F.obj ⟨0⟩).val.obj ⟨X⟩) : struct F where X n := (preimage hF X y n).1 x n := (preimage hF X y n).2 map n := (exists_effectiveEpi hF n _ _).choose_spec.choose effectiveEpi n := (exists_effectiveEpi hF n _ _).choose_spec.choose_spec.choose w n := (exists_effectiveEpi hF n _ _).choose_spec.choose_spec.choose_spec.choose_spec private noncomputable def preimageDiagram (X : C) (y : (F.obj ⟨0⟩).val.obj ⟨X⟩) : ℕᵒᵖ ⥤ C := Functor.ofOpSequence (preimageStruct hF X y).map variable [HasLimitsOfShape ℕᵒᵖ C] private noncomputable def cone (X : C) (y : (F.obj ⟨0⟩).val.obj ⟨X⟩) : Cone F where pt := ((coherentTopology C).yoneda).obj (limit (preimageDiagram hF X y)) π := NatTrans.ofOpSequence (fun n ↦ (coherentTopology C).yoneda.map (limit.π _ ⟨n⟩) ≫ ((coherentTopology C).yonedaEquiv).symm ((preimageStruct hF X y).x n)) (by intro n simp only [Functor.const_obj_obj, homOfLE_leOfHom, Functor.const_obj_map, Category.id_comp, Category.assoc, ← limit.w (preimageDiagram hF X y) (homOfLE (n.le_add_right 1)).op, homOfLE_leOfHom, Functor.map_comp] simp [GrothendieckTopology.yonedaEquiv_symm_naturality_left, GrothendieckTopology.yonedaEquiv_symm_naturality_right, preimageDiagram, (preimageStruct hF X y).w n]) variable (h : ∀ (G : ℕᵒᵖ ⥤ C), (∀ n, EffectiveEpi (G.map (homOfLE (Nat.le_succ n)).op)) → EffectiveEpi (limit.π G ⟨0⟩)) include hF h hc in lemma isLocallySurjective_π_app_zero_of_isLocallySurjective_map : Sheaf.IsLocallySurjective (c.π.app ⟨0⟩) := by rw [coherentTopology.isLocallySurjective_iff, regularTopology.isLocallySurjective_iff] intro X y have hh : EffectiveEpi (limit.π (preimageDiagram hF X y) ⟨0⟩) := h _ fun n ↦ by simpa [preimageDiagram] using (preimageStruct hF X y).effectiveEpi n refine ⟨limit (preimageDiagram hF X y), limit.π (preimageDiagram hF X y) ⟨0⟩, hh, (coherentTopology C).yonedaEquiv (hc.lift (cone hF X y )), (?_ : (c.π.app (op 0)).val.app _ _ = _)⟩ simp only [← (coherentTopology C).yonedaEquiv_comp, Functor.const_obj_obj, cone, IsLimit.fac, NatTrans.ofOpSequence_app, (coherentTopology C).yonedaEquiv_comp, (coherentTopology C).yonedaEquiv_yoneda_map] rfl include h in lemma epi_π_app_zero_of_epi [HasSheafify (coherentTopology C) (Type v)] [Balanced (Sheaf (coherentTopology C) (Type v))] [(coherentTopology C).WEqualsLocallyBijective (Type v)] {F : ℕᵒᵖ ⥤ Sheaf (coherentTopology C) (Type v)} {c : Cone F} (hc : IsLimit c) (hF : ∀ n, Epi (F.map (homOfLE (Nat.le_succ n)).op)) : Epi (c.π.app ⟨0⟩) := by simp_rw [← Sheaf.isLocallySurjective_iff_epi'] at hF ⊢ exact isLocallySurjective_π_app_zero_of_isLocallySurjective_map hc hF h end CategoryTheory.coherentTopology
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/ReflectsPreregular.lean
import Mathlib.CategoryTheory.EffectiveEpi.Enough import Mathlib.CategoryTheory.EffectiveEpi.Preserves import Mathlib.CategoryTheory.Sites.Coherent.RegularTopology /-! # Reflecting the property of being preregular We prove that given a fully faithful functor `F : C ⥤ D`, with `Preregular D`, such that for every object `X` of `D` there exists an object `W` of `C` with an effective epi `π : F.obj W ⟶ X`, the category `C` is `Preregular`. -/ namespace CategoryTheory variable {C D : Type*} [Category C] [Category D] (F : C ⥤ D) [F.PreservesEffectiveEpis] [F.ReflectsEffectiveEpis] [F.EffectivelyEnough] [Preregular D] [F.Full] [F.Faithful] include F in lemma Functor.reflects_preregular : Preregular C where exists_fac f g _ := by obtain ⟨W, f', _, i, w⟩ := Preregular.exists_fac (F.map f) (F.map g) refine ⟨_, F.preimage (F.effectiveEpiOver W ≫ f'), ⟨F.effectiveEpi_of_map _ ?_, F.preimage (F.effectiveEpiOver W ≫ i), ?_⟩⟩ · simp only [Functor.map_preimage] infer_instance · apply F.map_injective simp [w] end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/CoherentTopology.lean
import Mathlib.CategoryTheory.Sites.Coherent.CoherentSheaves import Mathlib.Data.Finite.Sigma /-! # Description of the covering sieves of the coherent topology This file characterises the covering sieves of the coherent topology. ## Main result * `coherentTopology.mem_sieves_iff_hasEffectiveEpiFamily`: a sieve is a covering sieve for the coherent topology if and only if it contains a finite effective epimorphic family. -/ namespace CategoryTheory variable {C : Type*} [Category C] [Precoherent C] {X : C} /-- For a precoherent category, any sieve that contains an `EffectiveEpiFamily` is a sieve of the coherent topology. Note: This is one direction of `mem_sieves_iff_hasEffectiveEpiFamily`, but is needed for the proof. -/ theorem coherentTopology.mem_sieves_of_hasEffectiveEpiFamily (S : Sieve X) : (∃ (α : Type) (_ : Finite α) (Y : α → C) (π : (a : α) → (Y a ⟶ X)), EffectiveEpiFamily Y π ∧ (∀ a : α, (S.arrows) (π a)) ) → (S ∈ (coherentTopology C) X) := by intro ⟨α, _, Y, π, hπ⟩ apply (coherentCoverage C).mem_toGrothendieck_sieves_of_superset (R := Presieve.ofArrows Y π) · exact fun _ _ h ↦ by cases h; exact hπ.2 _ · exact ⟨_, inferInstance, Y, π, rfl, hπ.1⟩ /-- Effective epi families in a precoherent category are transitive, in the sense that an `EffectiveEpiFamily` and an `EffectiveEpiFamily` over each member, the composition is an `EffectiveEpiFamily`. Note: The finiteness condition is an artifact of the proof and is probably unnecessary. -/ theorem EffectiveEpiFamily.transitive_of_finite {α : Type} [Finite α] {Y : α → C} (π : (a : α) → (Y a ⟶ X)) (h : EffectiveEpiFamily Y π) {β : α → Type} [∀ (a : α), Finite (β a)] {Y_n : (a : α) → β a → C} (π_n : (a : α) → (b : β a) → (Y_n a b ⟶ Y a)) (H : ∀ a, EffectiveEpiFamily (Y_n a) (π_n a)) : EffectiveEpiFamily (fun (c : Σ a, β a) => Y_n c.fst c.snd) (fun c => π_n c.fst c.snd ≫ π c.fst) := by rw [← Sieve.effectiveEpimorphic_family] suffices h₂ : (Sieve.generate (Presieve.ofArrows (fun (⟨a, b⟩ : Σ _, β _) => Y_n a b) (fun ⟨a,b⟩ => π_n a b ≫ π a))) ∈ (coherentTopology C) X by change Nonempty _ rw [← Sieve.forallYonedaIsSheaf_iff_colimit] exact fun W => coherentTopology.isSheaf_yoneda_obj W _ h₂ -- Show that a covering sieve is a colimit, which implies the original set of arrows is regular -- epimorphic. We use the transitivity property of saturation apply Coverage.Saturate.transitive X (Sieve.generate (Presieve.ofArrows Y π)) · apply Coverage.Saturate.of use α, inferInstance, Y, π · intro V f ⟨Y₁, h, g, ⟨hY, hf⟩⟩ rw [← hf, Sieve.pullback_comp] apply (coherentTopology C).pullback_stable' apply coherentTopology.mem_sieves_of_hasEffectiveEpiFamily -- Need to show that the pullback of the family `π_n` to a given `Y i` is effective epimorphic obtain ⟨i⟩ := hY exact ⟨β i, inferInstance, Y_n i, π_n i, H i, fun b ↦ ⟨Y_n i b, (𝟙 _), π_n i b ≫ π i, ⟨(⟨i, b⟩ : Σ (i : α), β i)⟩, by simp⟩⟩ instance precoherentEffectiveEpiFamilyCompEffectiveEpis {α : Type} [Finite α] {Y Z : α → C} (π : (a : α) → (Y a ⟶ X)) [EffectiveEpiFamily Y π] (f : (a : α) → Z a ⟶ Y a) [h : ∀ a, EffectiveEpi (f a)] : EffectiveEpiFamily _ fun a ↦ f a ≫ π a := by simp_rw [effectiveEpi_iff_effectiveEpiFamily] at h exact EffectiveEpiFamily.reindex (e := Equiv.sigmaPUnit α) _ _ (EffectiveEpiFamily.transitive_of_finite (β := fun _ ↦ Unit) _ inferInstance _ h) /-- A sieve belongs to the coherent topology if and only if it contains a finite `EffectiveEpiFamily`. -/ theorem coherentTopology.mem_sieves_iff_hasEffectiveEpiFamily (S : Sieve X) : (S ∈ (coherentTopology C) X) ↔ (∃ (α : Type) (_ : Finite α) (Y : α → C) (π : (a : α) → (Y a ⟶ X)), EffectiveEpiFamily Y π ∧ (∀ a : α, (S.arrows) (π a)) ) := by constructor · intro h induction h with | of Y T hS => obtain ⟨a, h, Y', π, h', _⟩ := hS refine ⟨a, h, Y', π, inferInstance, fun a' ↦ ?_⟩ obtain ⟨rfl, _⟩ := h' exact ⟨Y' a', 𝟙 Y' a', π a', Presieve.ofArrows.mk a', by simp⟩ | top Y => exact ⟨Unit, inferInstance, fun _ => Y, fun _ => (𝟙 Y), inferInstance, by simp⟩ | transitive Y R S _ _ a b => obtain ⟨α, w, Y₁, π, ⟨h₁,h₂⟩⟩ := a choose β _ Y_n π_n H using fun a => b (h₂ a) exact ⟨(Σ a, β a), inferInstance, fun ⟨a,b⟩ => Y_n a b, fun ⟨a, b⟩ => (π_n a b) ≫ (π a), EffectiveEpiFamily.transitive_of_finite _ h₁ _ (fun a => (H a).1), fun c => (H c.fst).2 c.snd⟩ · exact coherentTopology.mem_sieves_of_hasEffectiveEpiFamily S end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/ReflectsPrecoherent.lean
import Mathlib.CategoryTheory.EffectiveEpi.Enough import Mathlib.CategoryTheory.EffectiveEpi.Preserves import Mathlib.CategoryTheory.Sites.Coherent.CoherentTopology /-! # Reflecting the property of being precoherent We prove that given a fully faithful functor `F : C ⥤ D` which preserves and reflects finite effective epimorphic families, such that for every object `X` of `D` there exists an object `W` of `C` with an effective epi `π : F.obj W ⟶ X`, the category `C` is `Precoherent` whenever `D` is. -/ namespace CategoryTheory variable {C D : Type*} [Category C] [Category D] (F : C ⥤ D) [F.PreservesFiniteEffectiveEpiFamilies] [F.ReflectsFiniteEffectiveEpiFamilies] [F.EffectivelyEnough] [Precoherent D] [F.Full] [F.Faithful] include F in lemma Functor.reflects_precoherent : Precoherent C where pullback {B₁ B₂} f α _ X₁ π₁ _ := by obtain ⟨β, _, Y₂, τ₂, H, i, ι, hh⟩ := Precoherent.pullback (F.map f) _ _ (fun a ↦ F.map (π₁ a)) inferInstance refine ⟨β, inferInstance, _, fun b ↦ F.preimage (F.effectiveEpiOver (Y₂ b) ≫ τ₂ b), F.finite_effectiveEpiFamily_of_map _ _ ?_, ⟨i, fun b ↦ F.preimage (F.effectiveEpiOver (Y₂ b) ≫ ι b), ?_⟩⟩ · simp only [Functor.map_preimage] infer_instance · intro b apply F.map_injective simp [hh b] end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/Basic.lean
import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Sites.Coverage import Mathlib.CategoryTheory.EffectiveEpi.Basic /-! # The Coherent, Regular and Extensive Grothendieck Topologies This file defines three related Grothendieck topologies on a category `C`. The first one is called the *coherent* topology. For that to exist, the category `C` must satisfy a condition called `Precoherent C`, which is essentially the minimal requirement for the coherent coverage to exist. It means that finite effective epimorphic families can be "pulled back". Given such a category, the coherent coverage is `coherentCoverage C` and the corresponding Grothendieck topology is `coherentTopology C`. The covering sieves of this coverage are generated by presieves consisting of finite effective epimorphic families. The second one is called the *regular* topology and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The regular coverage is `regularCoverage C` and the corresponding Grothendieck topology is `regularTopology C`. The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The third one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. The extensive coverage is `extensiveCoverage C` and the corresponding Grothendieck topology is `extensiveTopology C`. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. ## References: - [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.1, Example 2.1.12. - [nLab, *Coherent Coverage*](https://ncatlab.org/nlab/show/coherent+coverage) -/ namespace CategoryTheory open Limits variable (C : Type*) [Category C] /-- The condition `Precoherent C` is essentially the minimal condition required to define the coherent coverage on `C`. -/ class Precoherent : Prop where /-- Given an effective epi family `π₁` over `B₁` and a morphism `f : B₂ ⟶ B₁`, there exists an effective epi family `π₂` over `B₂`, such that `π₂` factors through `π₁`. -/ pullback {B₁ B₂ : C} (f : B₂ ⟶ B₁) : ∀ (α : Type) [Finite α] (X₁ : α → C) (π₁ : (a : α) → (X₁ a ⟶ B₁)), EffectiveEpiFamily X₁ π₁ → ∃ (β : Type) (_ : Finite β) (X₂ : β → C) (π₂ : (b : β) → (X₂ b ⟶ B₂)), EffectiveEpiFamily X₂ π₂ ∧ ∃ (i : β → α) (ι : (b : β) → (X₂ b ⟶ X₁ (i b))), ∀ (b : β), ι b ≫ π₁ _ = π₂ _ ≫ f /-- The coherent coverage on a precoherent category `C`. -/ def coherentCoverage [Precoherent C] : Coverage C where coverings B := { S | ∃ (α : Type) (_ : Finite α) (X : α → C) (π : (a : α) → (X a ⟶ B)), S = Presieve.ofArrows X π ∧ EffectiveEpiFamily X π } pullback := by rintro B₁ B₂ f S ⟨α, _, X₁, π₁, rfl, hS⟩ obtain ⟨β,_,X₂,π₂,h,i,ι,hh⟩ := Precoherent.pullback f α X₁ π₁ hS refine ⟨Presieve.ofArrows X₂ π₂, ⟨β, inferInstance, X₂, π₂, rfl, h⟩, ?_⟩ rintro _ _ ⟨b⟩ exact ⟨(X₁ (i b)), ι _, π₁ _, ⟨_⟩, hh _⟩ /-- The coherent Grothendieck topology on a precoherent category `C`. -/ def coherentTopology [Precoherent C] : GrothendieckTopology C := (coherentCoverage C).toGrothendieck /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where coverings B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg cases hg refine ⟨Z, i, π, ⟨?_, this⟩⟩ cases hπ rw [Presieve.ofArrows_pUnit] exact Presieve.singleton.mk /-- The regular Grothendieck topology on a preregular category `C`. -/ def regularTopology [Preregular C] : GrothendieckTopology C := (regularCoverage C).toGrothendieck /-- The extensive coverage on an extensive category `C` TODO: use general colimit API instead of `IsIso (Sigma.desc π)` -/ def extensiveCoverage [FinitaryPreExtensive C] : Coverage C where coverings B := { S | ∃ (α : Type) (_ : Finite α) (X : α → C) (π : (a : α) → (X a ⟶ B)), S = Presieve.ofArrows X π ∧ IsIso (Sigma.desc π) } pullback := by intro X Y f S ⟨α, hα, Z, π, hS, h_iso⟩ let Z' : α → C := fun a ↦ pullback f (π a) let π' : (a : α) → Z' a ⟶ Y := fun a ↦ pullback.fst _ _ refine ⟨@Presieve.ofArrows C _ _ α Z' π', ⟨?_, ?_⟩⟩ · constructor exact ⟨hα, Z', π', ⟨by simp only, FinitaryPreExtensive.isIso_sigmaDesc_fst (fun x => π x) f h_iso⟩⟩ · intro W g hg rcases hg with ⟨a⟩ refine ⟨Z a, pullback.snd _ _, π a, ?_, by rw [CategoryTheory.Limits.pullback.condition]⟩ rw [hS] exact Presieve.ofArrows.mk a /-- The extensive Grothendieck topology on a finitary pre-extensive category `C`. -/ def extensiveTopology [FinitaryPreExtensive C] : GrothendieckTopology C := (extensiveCoverage C).toGrothendieck end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/ExtensiveSheaves.lean
import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.Sites.Canonical import Mathlib.CategoryTheory.Sites.Coherent.Basic import Mathlib.CategoryTheory.Sites.Preserves /-! # Sheaves for the extensive topology This file characterises sheaves for the extensive topology. ## Main result * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe w namespace CategoryTheory open Limits Presieve Opposite variable {C : Type*} [Category C] {D : Type*} [Category D] variable [FinitaryPreExtensive C] /-- A presieve is *extensive* if it is finite and its arrows induce an isomorphism from the coproduct to the target. -/ class Presieve.Extensive {X : C} (R : Presieve X) : Prop where /-- `R` consists of a finite collection of arrows that together induce an isomorphism from the coproduct of their sources. -/ arrows_nonempty_isColimit : ∃ (α : Type) (_ : Finite α) (Z : α → C) (π : (a : α) → (Z a ⟶ X)), R = Presieve.ofArrows Z π ∧ Nonempty (IsColimit (Cofan.mk X π)) instance {X : C} (S : Presieve X) [S.Extensive] : S.HasPairwisePullbacks where has_pullbacks := by obtain ⟨_, _, _, _, rfl, ⟨hc⟩⟩ := Presieve.Extensive.arrows_nonempty_isColimit (R := S) intro _ _ _ _ _ hg cases hg apply FinitaryPreExtensive.hasPullbacks_of_is_coproduct hc /-- A finite-product-preserving presheaf is a sheaf for the extensive topology on a category which is `FinitaryPreExtensive`. -/ theorem isSheafFor_extensive_of_preservesFiniteProducts {X : C} (S : Presieve X) [S.Extensive] (F : Cᵒᵖ ⥤ Type w) [PreservesFiniteProducts F] : S.IsSheafFor F := by obtain ⟨α, _, Z, π, rfl, ⟨hc⟩⟩ := Extensive.arrows_nonempty_isColimit (R := S) have : (ofArrows Z (Cofan.mk X π).inj).HasPairwisePullbacks := (inferInstance : (ofArrows Z π).HasPairwisePullbacks) cases nonempty_fintype α exact isSheafFor_of_preservesProduct F _ hc instance {α : Type} [Finite α] (Z : α → C) : (ofArrows Z (fun i ↦ Sigma.ι Z i)).Extensive := ⟨⟨α, inferInstance, Z, (fun i ↦ Sigma.ι Z i), rfl, ⟨coproductIsCoproduct _⟩⟩⟩ /-- Every Yoneda-presheaf is a sheaf for the extensive topology. -/ theorem extensiveTopology.isSheaf_yoneda_obj (W : C) : Presieve.IsSheaf (extensiveTopology C) (yoneda.obj W) := by rw [extensiveTopology, isSheaf_coverage] intro X R ⟨Y, α, Z, π, hR, hi⟩ have : IsIso (Sigma.desc (Cofan.inj (Cofan.mk X π))) := hi have : R.Extensive := ⟨Y, α, Z, π, hR, ⟨Cofan.isColimitOfIsIsoSigmaDesc (Cofan.mk X π)⟩⟩ exact isSheafFor_extensive_of_preservesFiniteProducts _ _ /-- The extensive topology on a finitary pre-extensive category is subcanonical. -/ instance extensiveTopology.subcanonical : (extensiveTopology C).Subcanonical := GrothendieckTopology.Subcanonical.of_isSheaf_yoneda_obj _ isSheaf_yoneda_obj variable [FinitaryExtensive C] /-- A presheaf of sets on a category which is `FinitaryExtensive` is a sheaf iff it preserves finite products. -/ theorem Presieve.isSheaf_iff_preservesFiniteProducts (F : Cᵒᵖ ⥤ Type w) : Presieve.IsSheaf (extensiveTopology C) F ↔ PreservesFiniteProducts F := by refine ⟨fun hF ↦ ⟨fun n ↦ ⟨fun {K} ↦ ?_⟩⟩, fun hF ↦ ?_⟩ · rw [extensiveTopology, isSheaf_coverage] at hF let Z : Fin n → C := fun i ↦ unop (K.obj ⟨i⟩) have : (ofArrows Z (Cofan.mk (∐ Z) (Sigma.ι Z)).inj).HasPairwisePullbacks := inferInstanceAs (ofArrows Z (Sigma.ι Z)).HasPairwisePullbacks have : ∀ (i : Fin n), Mono (Cofan.inj (Cofan.mk (∐ Z) (Sigma.ι Z)) i) := inferInstanceAs <| ∀ (i : Fin n), Mono (Sigma.ι Z i) let i : K ≅ Discrete.functor (fun i ↦ op (Z i)) := Discrete.natIsoFunctor let _ : PreservesLimit (Discrete.functor (fun i ↦ op (Z i))) F := Presieve.preservesProduct_of_isSheafFor F ?_ initialIsInitial _ (coproductIsCoproduct Z) (FinitaryExtensive.isPullback_initial_to_sigma_ι Z) (hF (Presieve.ofArrows Z (fun i ↦ Sigma.ι Z i)) ?_) · exact preservesLimit_of_iso_diagram F i.symm · apply hF refine ⟨Empty, inferInstance, Empty.elim, IsEmpty.elim inferInstance, rfl, ⟨default,?_, ?_⟩⟩ · ext b cases b · simp only [eq_iff_true_of_subsingleton] · refine ⟨Fin n, inferInstance, Z, (fun i ↦ Sigma.ι Z i), rfl, ?_⟩ suffices Sigma.desc (fun i ↦ Sigma.ι Z i) = 𝟙 _ by rw [this]; infer_instance ext simp · rw [extensiveTopology, Presieve.isSheaf_coverage] intro X R ⟨Y, α, Z, π, hR, hi⟩ have : IsIso (Sigma.desc (Cofan.inj (Cofan.mk X π))) := hi have : R.Extensive := ⟨Y, α, Z, π, hR, ⟨Cofan.isColimitOfIsIsoSigmaDesc (Cofan.mk X π)⟩⟩ exact isSheafFor_extensive_of_preservesFiniteProducts R F /-- A presheaf on a category which is `FinitaryExtensive` is a sheaf iff it preserves finite products. -/ theorem Presheaf.isSheaf_iff_preservesFiniteProducts (F : Cᵒᵖ ⥤ D) : IsSheaf (extensiveTopology C) F ↔ PreservesFiniteProducts F := by constructor · intro h rw [IsSheaf] at h refine ⟨fun n ↦ ⟨fun {K} ↦ ⟨fun {c} hc ↦ ?_⟩⟩⟩ constructor apply coyonedaJointlyReflectsLimits intro ⟨E⟩ specialize h E rw [Presieve.isSheaf_iff_preservesFiniteProducts] at h exact isLimitOfPreserves (F.comp (coyoneda.obj ⟨E⟩)) hc · intro _ E rw [Presieve.isSheaf_iff_preservesFiniteProducts] exact ⟨inferInstance⟩ instance (F : Sheaf (extensiveTopology C) D) : PreservesFiniteProducts F.val := (Presheaf.isSheaf_iff_preservesFiniteProducts F.val).mp F.cond end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/ExtensiveTopology.lean
import Mathlib.CategoryTheory.Sites.Coherent.Basic import Mathlib.Data.Finite.Sigma /-! # Description of the covering sieves of the extensive topology This file characterises the covering sieves of the extensive topology. ## Main result * `extensiveTopology.mem_sieves_iff_contains_colimit_cofan`: a sieve is a covering sieve for the extensive topology if and only if it contains a finite family of morphisms with fixed target exhibiting the target as a coproduct of the sources. -/ open CategoryTheory Limits variable {C : Type*} [Category C] [FinitaryPreExtensive C] namespace CategoryTheory lemma extensiveTopology.mem_sieves_iff_contains_colimit_cofan {X : C} (S : Sieve X) : S ∈ (extensiveTopology C) X ↔ (∃ (α : Type) (_ : Finite α) (Y : α → C) (π : (a : α) → (Y a ⟶ X)), Nonempty (IsColimit (Cofan.mk X π)) ∧ (∀ a : α, (S.arrows) (π a))) := by constructor · intro h induction h with | of X S hS => obtain ⟨α, _, Y, π, h, h'⟩ := hS refine ⟨α, inferInstance, Y, π, ?_, fun a ↦ ?_⟩ · have : IsIso (Sigma.desc (Cofan.mk X π).inj) := by simpa using h' exact ⟨Cofan.isColimitOfIsIsoSigmaDesc (Cofan.mk X π)⟩ · obtain ⟨rfl, _⟩ := h exact ⟨Y a, 𝟙 Y a, π a, Presieve.ofArrows.mk a, by simp⟩ | top X => refine ⟨Unit, inferInstance, fun _ => X, fun _ => (𝟙 X), ⟨?_⟩, by simp⟩ have : IsIso (Sigma.desc (Cofan.mk X fun (_ : Unit) ↦ 𝟙 X).inj) := by have : IsIso (coproductUniqueIso (fun () => X)).hom := inferInstance exact this exact Cofan.isColimitOfIsIsoSigmaDesc (Cofan.mk X _) | transitive X R S _ _ a b => obtain ⟨α, w, Y₁, π, h, h'⟩ := a choose β _ Y_n π_n H using fun a => b (h' a) exact ⟨(Σ a, β a), inferInstance, fun ⟨a,b⟩ => Y_n a b, fun ⟨a, b⟩ => (π_n a b) ≫ (π a), ⟨Limits.Cofan.isColimitTrans _ h.some _ (fun a ↦ (H a).1.some)⟩, fun c => (H c.fst).2 c.snd⟩ · intro ⟨α, _, Y, π, h, h'⟩ apply (extensiveCoverage C).mem_toGrothendieck_sieves_of_superset (R := Presieve.ofArrows Y π) · exact fun _ _ hh ↦ by cases hh; exact h' _ · refine ⟨α, inferInstance, Y, π, rfl, ?_⟩ rw [show IsIso (Sigma.desc π) ↔ _ from Limits.Cofan.isColimit_iff_isIso_sigmaDesc (c := Cofan.mk X π)] exact h end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/CoherentSheaves.lean
import Mathlib.CategoryTheory.Sites.Canonical import Mathlib.CategoryTheory.Sites.Coherent.Basic import Mathlib.CategoryTheory.Sites.EffectiveEpimorphic /-! # Sheaves for the coherent topology This file characterises sheaves for the coherent topology ## Main result * `isSheaf_coherent`: a presheaf of types for the is a sheaf for the coherent topology if and only if it satisfies the sheaf condition with respect to every presieve consisting of a finite effective epimorphic family. -/ namespace CategoryTheory variable {C : Type*} [Category C] [Precoherent C] universe w in lemma isSheaf_coherent (P : Cᵒᵖ ⥤ Type w) : Presieve.IsSheaf (coherentTopology C) P ↔ (∀ (B : C) (α : Type) [Finite α] (X : α → C) (π : (a : α) → (X a ⟶ B)), EffectiveEpiFamily X π → (Presieve.ofArrows X π).IsSheafFor P) := by constructor · intro hP B α _ X π h simp only [coherentTopology, Presieve.isSheaf_coverage] at hP apply hP exact ⟨α, inferInstance, X, π, rfl, h⟩ · intro h simp only [coherentTopology, Presieve.isSheaf_coverage] rintro B S ⟨α, _, X, π, rfl, hS⟩ exact h _ _ _ _ hS namespace coherentTopology /-- Every Yoneda-presheaf is a sheaf for the coherent topology. -/ theorem isSheaf_yoneda_obj (W : C) : Presieve.IsSheaf (coherentTopology C) (yoneda.obj W) := by rw [isSheaf_coherent] intro X α _ Y π H have h_colim := isColimitOfEffectiveEpiFamilyStruct Y π H.effectiveEpiFamily.some rw [← Sieve.generateFamily_eq] at h_colim intro x hx let x_ext := Presieve.FamilyOfElements.sieveExtend x have hx_ext := Presieve.FamilyOfElements.Compatible.sieveExtend hx let S := Sieve.generate (Presieve.ofArrows Y π) obtain ⟨t, t_amalg, t_uniq⟩ : ∃! t, x_ext.IsAmalgamation t := (Sieve.forallYonedaIsSheaf_iff_colimit S).mpr ⟨h_colim⟩ W x_ext hx_ext refine ⟨t, ?_, ?_⟩ · convert Presieve.isAmalgamation_restrict (Sieve.le_generate (Presieve.ofArrows Y π)) _ _ t_amalg exact (Presieve.restrict_extend hx).symm · exact fun y hy ↦ t_uniq y <| Presieve.isAmalgamation_sieveExtend x y hy variable (C) in /-- The coherent topology on a precoherent category is subcanonical. -/ instance subcanonical : (coherentTopology C).Subcanonical := GrothendieckTopology.Subcanonical.of_isSheaf_yoneda_obj _ isSheaf_yoneda_obj end coherentTopology end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/Equivalence.lean
import Mathlib.CategoryTheory.Sites.Coherent.SheafComparison import Mathlib.CategoryTheory.Sites.Equivalence /-! # Coherence and equivalence of categories This file proves that the coherent and regular topologies transfer nicely along equivalences of categories. -/ namespace CategoryTheory variable {C : Type*} [Category C] open GrothendieckTopology namespace Equivalence variable {D : Type*} [Category D] section Coherent variable [Precoherent C] /-- `Precoherent` is preserved by equivalence of categories. -/ theorem precoherent (e : C ≌ D) : Precoherent D := e.inverse.reflects_precoherent instance [EssentiallySmall C] : Precoherent (SmallModel C) := (equivSmallModel C).precoherent instance (e : C ≌ D) : haveI := precoherent e e.inverse.IsDenseSubsite (coherentTopology D) (coherentTopology C) where functorPushforward_mem_iff := by rw [coherentTopology.eq_induced e.inverse] simp only [Functor.mem_inducedTopology_sieves_iff, implies_true] variable (A : Type*) [Category A] /-- Equivalent precoherent categories give equivalent coherent toposes. -/ @[simps!] def sheafCongrPrecoherent (e : C ≌ D) : haveI := e.precoherent Sheaf (coherentTopology C) A ≌ Sheaf (coherentTopology D) A := e.sheafCongr _ _ _ open Presheaf /-- The coherent sheaf condition can be checked after precomposing with the equivalence. -/ theorem precoherent_isSheaf_iff (e : C ≌ D) (F : Cᵒᵖ ⥤ A) : haveI := e.precoherent IsSheaf (coherentTopology C) F ↔ IsSheaf (coherentTopology D) (e.inverse.op ⋙ F) := by refine ⟨fun hF ↦ ((e.sheafCongrPrecoherent A).functor.obj ⟨F, hF⟩).cond, fun hF ↦ ?_⟩ rw [isSheaf_of_iso_iff (P' := e.functor.op ⋙ e.inverse.op ⋙ F)] · exact (e.sheafCongrPrecoherent A).inverse.obj ⟨e.inverse.op ⋙ F, hF⟩ |>.cond · exact Functor.isoWhiskerRight e.op.unitIso F /-- The coherent sheaf condition on an essentially small site can be checked after precomposing with the equivalence with a small category. -/ theorem precoherent_isSheaf_iff_of_essentiallySmall [EssentiallySmall C] (F : Cᵒᵖ ⥤ A) : IsSheaf (coherentTopology C) F ↔ IsSheaf (coherentTopology (SmallModel C)) ((equivSmallModel C).inverse.op ⋙ F) := precoherent_isSheaf_iff _ _ _ end Coherent section Regular variable [Preregular C] /-- `Preregular` is preserved by equivalence of categories. -/ theorem preregular (e : C ≌ D) : Preregular D := e.inverse.reflects_preregular instance [EssentiallySmall C] : Preregular (SmallModel C) := (equivSmallModel C).preregular instance (e : C ≌ D) : haveI := preregular e e.inverse.IsDenseSubsite (regularTopology D) (regularTopology C) where functorPushforward_mem_iff := by rw [regularTopology.eq_induced e.inverse] simp only [Functor.mem_inducedTopology_sieves_iff, implies_true] variable (A : Type*) [Category A] /-- Equivalent preregular categories give equivalent regular toposes. -/ @[simps!] def sheafCongrPreregular (e : C ≌ D) : haveI := e.preregular Sheaf (regularTopology C) A ≌ Sheaf (regularTopology D) A := e.sheafCongr _ _ _ open Presheaf /-- The regular sheaf condition can be checked after precomposing with the equivalence. -/ theorem preregular_isSheaf_iff (e : C ≌ D) (F : Cᵒᵖ ⥤ A) : haveI := e.preregular IsSheaf (regularTopology C) F ↔ IsSheaf (regularTopology D) (e.inverse.op ⋙ F) := by refine ⟨fun hF ↦ ((e.sheafCongrPreregular A).functor.obj ⟨F, hF⟩).cond, fun hF ↦ ?_⟩ rw [isSheaf_of_iso_iff (P' := e.functor.op ⋙ e.inverse.op ⋙ F)] · exact (e.sheafCongrPreregular A).inverse.obj ⟨e.inverse.op ⋙ F, hF⟩ |>.cond · exact Functor.isoWhiskerRight e.op.unitIso F /-- The regular sheaf condition on an essentially small site can be checked after precomposing with the equivalence with a small category. -/ theorem preregular_isSheaf_iff_of_essentiallySmall [EssentiallySmall C] (F : Cᵒᵖ ⥤ A) : IsSheaf (regularTopology C) F ↔ IsSheaf (regularTopology (SmallModel C)) ((equivSmallModel C).inverse.op ⋙ F) := preregular_isSheaf_iff _ _ _ end Regular end Equivalence end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/RegularSheaves.lean
import Mathlib.CategoryTheory.EffectiveEpi.Preserves import Mathlib.CategoryTheory.Limits.Final.ParallelPair import Mathlib.CategoryTheory.Preadditive.Projective.Basic import Mathlib.CategoryTheory.Sites.Canonical import Mathlib.CategoryTheory.Sites.Coherent.Basic import Mathlib.CategoryTheory.Sites.EffectiveEpimorphic /-! # Sheaves for the regular topology This file characterises sheaves for the regular topology. ## Main results * `equalizerCondition_iff_isSheaf`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. -/ namespace CategoryTheory open Limits variable {C D E : Type*} [Category C] [Category D] [Category E] open Opposite Presieve Functor /-- A presieve is *regular* if it consists of a single effective epimorphism. -/ class Presieve.regular {X : C} (R : Presieve X) : Prop where /-- `R` consists of a single epimorphism. -/ single_epi : ∃ (Y : C) (f : Y ⟶ X), R = Presieve.ofArrows (fun (_ : Unit) ↦ Y) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f namespace regularTopology lemma equalizerCondition_w (P : Cᵒᵖ ⥤ D) {X B : C} {π : X ⟶ B} (c : PullbackCone π π) : P.map π.op ≫ P.map c.fst.op = P.map π.op ≫ P.map c.snd.op := by simp only [← Functor.map_comp, ← op_comp, c.condition] /-- A contravariant functor on `C` satisfies `SingleEqualizerCondition` with respect to a morphism `π` if it takes its kernel pair to an equalizer diagram. -/ def SingleEqualizerCondition (P : Cᵒᵖ ⥤ D) ⦃X B : C⦄ (π : X ⟶ B) : Prop := ∀ (c : PullbackCone π π) (_ : IsLimit c), Nonempty (IsLimit (Fork.ofι (P.map π.op) (equalizerCondition_w P c))) /-- A contravariant functor on `C` satisfies `EqualizerCondition` if it takes kernel pairs of effective epimorphisms to equalizer diagrams. -/ def EqualizerCondition (P : Cᵒᵖ ⥤ D) : Prop := ∀ ⦃X B : C⦄ (π : X ⟶ B) [EffectiveEpi π], SingleEqualizerCondition P π /-- The equalizer condition is preserved by natural isomorphism. -/ theorem equalizerCondition_of_natIso {P P' : Cᵒᵖ ⥤ D} (i : P ≅ P') (hP : EqualizerCondition P) : EqualizerCondition P' := fun X B π _ c hc ↦ ⟨Fork.isLimitOfIsos _ (hP π c hc).some _ (i.app _) (i.app _) (i.app _)⟩ /-- Precomposing with a pullback-preserving functor preserves the equalizer condition. -/ theorem equalizerCondition_precomp_of_preservesPullback (P : Cᵒᵖ ⥤ D) (F : E ⥤ C) [∀ {X B} (π : X ⟶ B) [EffectiveEpi π], PreservesLimit (cospan π π) F] [F.PreservesEffectiveEpis] (hP : EqualizerCondition P) : EqualizerCondition (F.op ⋙ P) := by intro X B π _ c hc have h : P.map (F.map π).op = (F.op ⋙ P).map π.op := by simp refine ⟨(IsLimit.equivIsoLimit (ForkOfι.ext ?_ _ h)) ?_⟩ · simp only [Functor.comp_map, op_map, Quiver.Hom.unop_op, ← map_comp, ← op_comp, c.condition] · refine (hP (F.map π) (PullbackCone.mk (F.map c.fst) (F.map c.snd) ?_) ?_).some · simp only [← map_comp, c.condition] · exact (isLimitMapConePullbackConeEquiv F c.condition) (isLimitOfPreserves F (hc.ofIsoLimit (PullbackCone.ext (Iso.refl _) (by simp) (by simp)))) /-- The canonical map to the explicit equalizer. -/ def MapToEqualizer (P : Cᵒᵖ ⥤ Type*) {W X B : C} (f : X ⟶ B) (g₁ g₂ : W ⟶ X) (w : g₁ ≫ f = g₂ ≫ f) : P.obj (op B) → { x : P.obj (op X) | P.map g₁.op x = P.map g₂.op x } := fun t ↦ ⟨P.map f.op t, by simp only [Set.mem_setOf_eq, ← FunctorToTypes.map_comp_apply, ← op_comp, w]⟩ theorem EqualizerCondition.bijective_mapToEqualizer_pullback (P : Cᵒᵖ ⥤ Type*) (hP : EqualizerCondition P) : ∀ (X B : C) (π : X ⟶ B) [EffectiveEpi π] [HasPullback π π], Function.Bijective (MapToEqualizer P π (pullback.fst π π) (pullback.snd π π) pullback.condition) := by intro X B π _ _ specialize hP π _ (pullbackIsPullback π π) rw [Types.type_equalizer_iff_unique] at hP rw [Function.bijective_iff_existsUnique] intro ⟨b, hb⟩ obtain ⟨a, ha₁, ha₂⟩ := hP b hb refine ⟨a, ?_, ?_⟩ · simpa [MapToEqualizer] using ha₁ · simpa [MapToEqualizer] using ha₂ theorem EqualizerCondition.mk (P : Cᵒᵖ ⥤ Type*) (hP : ∀ (X B : C) (π : X ⟶ B) [EffectiveEpi π] [HasPullback π π], Function.Bijective (MapToEqualizer P π (pullback.fst π π) (pullback.snd π π) pullback.condition)) : EqualizerCondition P := by intro X B π _ c hc have : HasPullback π π := ⟨c, hc⟩ specialize hP X B π rw [Types.type_equalizer_iff_unique] rw [Function.bijective_iff_existsUnique] at hP intro b hb have h₁ : ((pullbackIsPullback π π).conePointUniqueUpToIso hc).hom ≫ c.fst = pullback.fst π π := by simp have hb' : P.map (pullback.fst π π).op b = P.map (pullback.snd _ _).op b := by rw [← h₁, op_comp, FunctorToTypes.map_comp_apply, hb] simp [← FunctorToTypes.map_comp_apply, ← op_comp] obtain ⟨a, ha₁, ha₂⟩ := hP ⟨b, hb'⟩ refine ⟨a, ?_, ?_⟩ · simpa [MapToEqualizer] using ha₁ · simpa [MapToEqualizer] using ha₂ lemma equalizerCondition_w' (P : Cᵒᵖ ⥤ Type*) {X B : C} (π : X ⟶ B) [HasPullback π π] : P.map π.op ≫ P.map (pullback.fst π π).op = P.map π.op ≫ P.map (pullback.snd π π).op := by simp only [← Functor.map_comp, ← op_comp, pullback.condition] lemma mapToEqualizer_eq_comp (P : Cᵒᵖ ⥤ Type*) {X B : C} (π : X ⟶ B) [HasPullback π π] : MapToEqualizer P π (pullback.fst π π) (pullback.snd π π) pullback.condition = equalizer.lift (P.map π.op) (equalizerCondition_w' P π) ≫ (Types.equalizerIso _ _).hom := by rw [← Iso.comp_inv_eq (α := Types.equalizerIso _ _)] apply equalizer.hom_ext aesop /-- An alternative phrasing of the explicit equalizer condition, using more categorical language. -/ theorem equalizerCondition_iff_isIso_lift (P : Cᵒᵖ ⥤ Type*) : EqualizerCondition P ↔ ∀ (X B : C) (π : X ⟶ B) [EffectiveEpi π] [HasPullback π π], IsIso (equalizer.lift (P.map π.op) (equalizerCondition_w' P π)) := by constructor · intro hP X B π _ _ have h := hP.bijective_mapToEqualizer_pullback _ X B π rw [← isIso_iff_bijective, mapToEqualizer_eq_comp] at h exact IsIso.of_isIso_comp_right (equalizer.lift (P.map π.op) (equalizerCondition_w' P π)) (Types.equalizerIso _ _).hom · intro hP apply EqualizerCondition.mk intro X B π _ _ rw [mapToEqualizer_eq_comp, ← isIso_iff_bijective] infer_instance /-- `P` satisfies the equalizer condition iff its precomposition by an equivalence does. -/ theorem equalizerCondition_iff_of_equivalence (P : Cᵒᵖ ⥤ D) (e : C ≌ E) : EqualizerCondition P ↔ EqualizerCondition (e.op.inverse ⋙ P) := ⟨fun h ↦ equalizerCondition_precomp_of_preservesPullback P e.inverse h, fun h ↦ equalizerCondition_of_natIso (e.op.funInvIdAssoc P) (equalizerCondition_precomp_of_preservesPullback (e.op.inverse ⋙ P) e.functor h)⟩ open WalkingParallelPair WalkingParallelPairHom in theorem parallelPair_pullback_initial {X B : C} (π : X ⟶ B) (c : PullbackCone π π) (hc : IsLimit c) : (parallelPair (C := (Sieve.ofArrows (fun (_ : Unit) => X) (fun _ => π)).arrows.categoryᵒᵖ) (Y := op ((Presieve.categoryMk _ (c.fst ≫ π) ⟨_, c.fst, π, ofArrows.mk (), rfl⟩))) (X := op ((Presieve.categoryMk _ π (Sieve.ofArrows_mk _ _ Unit.unit)))) (Quiver.Hom.op (Over.homMk c.fst)) (Quiver.Hom.op (Over.homMk c.snd c.condition.symm))).Initial := by apply Limits.parallelPair_initial_mk · intro ⟨Z⟩ obtain ⟨_, f, g, ⟨⟩, hh⟩ := Z.property let X' : (Presieve.ofArrows (fun () ↦ X) (fun () ↦ π)).category := Presieve.categoryMk _ π (ofArrows.mk ()) let f' : Z.obj.left ⟶ X'.obj.left := f exact ⟨(Over.homMk f').op⟩ · intro ⟨Z⟩ ⟨i⟩ ⟨j⟩ let ij := PullbackCone.IsLimit.lift hc i.left j.left (by erw [i.w, j.w]; rfl) refine ⟨Quiver.Hom.op (Over.homMk ij (by simpa [ij] using i.w)), ?_, ?_⟩ all_goals congr all_goals exact Comma.hom_ext _ _ (by erw [Over.comp_left]; simp [ij]) rfl /-- Given a limiting pullback cone, the fork in `SingleEqualizerCondition` is limiting iff the diagram in `Presheaf.isSheaf_iff_isLimit_coverage` is limiting. -/ noncomputable def isLimit_forkOfι_equiv (P : Cᵒᵖ ⥤ D) {X B : C} (π : X ⟶ B) (c : PullbackCone π π) (hc : IsLimit c) : IsLimit (Fork.ofι (P.map π.op) (equalizerCondition_w P c)) ≃ IsLimit (P.mapCone (Sieve.ofArrows (fun (_ : Unit) ↦ X) fun _ ↦ π).arrows.cocone.op) := by let S := (Sieve.ofArrows (fun (_ : Unit) => X) (fun _ => π)).arrows let X' := S.categoryMk π ⟨_, 𝟙 _, π, ofArrows.mk (), Category.id_comp _⟩ let P' := S.categoryMk (c.fst ≫ π) ⟨_, c.fst, π, ofArrows.mk (), rfl⟩ let fst : P' ⟶ X' := Over.homMk c.fst let snd : P' ⟶ X' := Over.homMk c.snd c.condition.symm let F : S.categoryᵒᵖ ⥤ D := S.diagram.op ⋙ P let G := parallelPair (P.map c.fst.op) (P.map c.snd.op) let H := parallelPair fst.op snd.op have : H.Initial := parallelPair_pullback_initial π c hc let i : H ⋙ F ≅ G := parallelPair.ext (Iso.refl _) (Iso.refl _) (by aesop) (by aesop) refine (IsLimit.equivOfNatIsoOfIso i.symm _ _ ?_).trans (Functor.Initial.isLimitWhiskerEquiv H _) refine Cones.ext (Iso.refl _) ?_ rintro ⟨_ | _⟩ all_goals aesop lemma equalizerConditionMap_iff_nonempty_isLimit (P : Cᵒᵖ ⥤ D) ⦃X B : C⦄ (π : X ⟶ B) [HasPullback π π] : SingleEqualizerCondition P π ↔ Nonempty (IsLimit (P.mapCone (Sieve.ofArrows (fun (_ : Unit) => X) (fun _ => π)).arrows.cocone.op)) := by constructor · intro h exact ⟨isLimit_forkOfι_equiv _ _ _ (pullbackIsPullback π π) (h _ (pullbackIsPullback π π)).some⟩ · intro ⟨h⟩ exact fun c hc ↦ ⟨(isLimit_forkOfι_equiv _ _ _ hc).symm h⟩ lemma equalizerCondition_iff_isSheaf (F : Cᵒᵖ ⥤ D) [Preregular C] [∀ {Y X : C} (f : Y ⟶ X) [EffectiveEpi f], HasPullback f f] : EqualizerCondition F ↔ Presheaf.IsSheaf (regularTopology C) F := by dsimp [regularTopology] rw [Presheaf.isSheaf_iff_isLimit_coverage] constructor · rintro hF X _ ⟨Y, f, rfl, _⟩ exact (equalizerConditionMap_iff_nonempty_isLimit F f).1 (hF f) · intro hF Y X f _ exact (equalizerConditionMap_iff_nonempty_isLimit F f).2 (hF _ ⟨_, f, rfl, inferInstance⟩) lemma isSheafFor_regular_of_projective {X : C} (S : Presieve X) [S.regular] [Projective X] (F : Cᵒᵖ ⥤ Type*) : S.IsSheafFor F := by obtain ⟨Y, f, rfl, hf⟩ := Presieve.regular.single_epi (R := S) rw [isSheafFor_arrows_iff] refine fun x hx ↦ ⟨F.map (Projective.factorThru (𝟙 _) f).op <| x (), fun _ ↦ ?_, fun y h ↦ ?_⟩ · simpa using (hx () () Y (𝟙 Y) (f ≫ (Projective.factorThru (𝟙 _) f)) (by simp)).symm · simp only [← h (), ← FunctorToTypes.map_comp_apply, ← op_comp, Projective.factorThru_comp, op_id, FunctorToTypes.map_id_apply] /-- Every presheaf is a sheaf for the regular topology if every object of `C` is projective. -/ theorem isSheaf_of_projective (F : Cᵒᵖ ⥤ D) [Preregular C] [∀ (X : C), Projective X] : Presheaf.IsSheaf (regularTopology C) F := fun _ ↦ (isSheaf_coverage _ _).mpr fun S ⟨_, h⟩ ↦ have : S.regular := ⟨_, h⟩ isSheafFor_regular_of_projective _ _ /-- Every Yoneda-presheaf is a sheaf for the regular topology. -/ lemma isSheaf_yoneda_obj [Preregular C] (W : C) : Presieve.IsSheaf (regularTopology C) (yoneda.obj W) := by rw [regularTopology, isSheaf_coverage] intro X S ⟨_, hS⟩ have : S.regular := ⟨_, hS⟩ obtain ⟨Y, f, rfl, hf⟩ := Presieve.regular.single_epi (R := S) have h_colim := isColimitOfEffectiveEpiStruct f hf.effectiveEpi.some rw [← Sieve.generateSingleton_eq, ← Presieve.ofArrows_pUnit] at h_colim intro x hx let x_ext := Presieve.FamilyOfElements.sieveExtend x have hx_ext := Presieve.FamilyOfElements.Compatible.sieveExtend hx let S := Sieve.generate (Presieve.ofArrows (fun () ↦ Y) (fun () ↦ f)) obtain ⟨t, t_amalg, t_uniq⟩ := (Sieve.forallYonedaIsSheaf_iff_colimit S).mpr ⟨h_colim⟩ W x_ext hx_ext refine ⟨t, ?_, ?_⟩ · convert Presieve.isAmalgamation_restrict (Sieve.le_generate (Presieve.ofArrows (fun () ↦ Y) (fun () ↦ f))) _ _ t_amalg exact (Presieve.restrict_extend hx).symm · exact fun y hy ↦ t_uniq y <| Presieve.isAmalgamation_sieveExtend x y hy /-- The regular topology on any preregular category is subcanonical. -/ instance subcanonical [Preregular C] : (regularTopology C).Subcanonical := GrothendieckTopology.Subcanonical.of_isSheaf_yoneda_obj _ isSheaf_yoneda_obj end regularTopology end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/Comparison.lean
import Mathlib.CategoryTheory.Sites.Coherent.Basic import Mathlib.CategoryTheory.EffectiveEpi.Comp import Mathlib.CategoryTheory.EffectiveEpi.Extensive /-! # Connections between the regular, extensive and coherent topologies This file compares the regular, extensive and coherent topologies. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. -/ namespace CategoryTheory open Limits GrothendieckTopology Sieve variable (C : Type*) [Category C] instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b instance [FinitaryPreExtensive C] [Preregular C] : Precoherent C where pullback {B₁ B₂} f α _ X₁ π₁ h := by refine ⟨α, inferInstance, ?_⟩ obtain ⟨Y, g, _, g', hg⟩ := Preregular.exists_fac f (Sigma.desc π₁) let X₂ := fun a ↦ pullback g' (Sigma.ι X₁ a) let π₂ := fun a ↦ pullback.fst g' (Sigma.ι X₁ a) ≫ g let π' := fun a ↦ pullback.fst g' (Sigma.ι X₁ a) have _ := FinitaryPreExtensive.isIso_sigmaDesc_fst (fun a ↦ Sigma.ι X₁ a) g' inferInstance refine ⟨X₂, π₂, ?_, ?_⟩ · have : (Sigma.desc π' ≫ g) = Sigma.desc π₂ := by ext; simp [π₂, π'] rw [← effectiveEpi_desc_iff_effectiveEpiFamily, ← this] infer_instance · refine ⟨id, fun b ↦ pullback.snd _ _, fun b ↦ ?_⟩ simp only [X₂, π₂, id_eq, Category.assoc, ← hg] rw [← Category.assoc, pullback.condition] simp /-- The union of the extensive and regular coverages generates the coherent topology on `C`. -/ theorem extensive_regular_generate_coherent [Preregular C] [FinitaryPreExtensive C] : ((extensiveCoverage C) ⊔ (regularCoverage C)).toGrothendieck = (coherentTopology C) := by ext B S refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · induction h with | of Y T hT => apply Coverage.Saturate.of simp only [Coverage.sup_covering, Set.mem_union] at hT exact Or.elim hT (fun ⟨α, x, X, π, ⟨h, _⟩⟩ ↦ ⟨α, x, X, π, ⟨h, inferInstance⟩⟩) (fun ⟨Z, f, ⟨h, _⟩⟩ ↦ ⟨Unit, inferInstance, fun _ ↦ Z, fun _ ↦ f, ⟨h, inferInstance⟩⟩) | top => apply Coverage.Saturate.top | transitive Y T => apply Coverage.Saturate.transitive Y T<;> [assumption; assumption] · induction h with | of Y T hT => obtain ⟨I, _, X, f, rfl, hT⟩ := hT apply Coverage.Saturate.transitive Y (generate (Presieve.ofArrows (fun (_ : Unit) ↦ (∐ fun (i : I) => X i)) (fun (_ : Unit) ↦ Sigma.desc f))) · apply Coverage.Saturate.of simp only [Coverage.sup_covering, extensiveCoverage, regularCoverage, Set.mem_union, Set.mem_setOf_eq] exact Or.inr ⟨_, Sigma.desc f, ⟨rfl, inferInstance⟩⟩ · rintro R g ⟨W, ψ, σ, ⟨⟩, rfl⟩ change _ ∈ ((extensiveCoverage C) ⊔ (regularCoverage C)).toGrothendieck R rw [Sieve.pullback_comp] apply pullback_stable have : generate (Presieve.ofArrows X fun (i : I) ↦ Sigma.ι X i) ≤ (generate (Presieve.ofArrows X f)).pullback (Sigma.desc f) := by rintro Q q ⟨E, e, r, ⟨hq, rfl⟩⟩ exact ⟨E, e, r ≫ (Sigma.desc f), by cases hq; simpa using Presieve.ofArrows.mk _, by simp⟩ apply Coverage.saturate_of_superset _ this apply Coverage.Saturate.of refine Or.inl ⟨I, inferInstance, _, _, ⟨rfl, ?_⟩⟩ convert IsIso.id _ aesop | top => apply Coverage.Saturate.top | transitive Y T => apply Coverage.Saturate.transitive Y T<;> [assumption; assumption] end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Coherent/RegularTopology.lean
import Mathlib.CategoryTheory.Sites.Coherent.RegularSheaves /-! # Description of the covering sieves of the regular topology This file characterises the covering sieves of the regular topology. ## Main result * `regularTopology.mem_sieves_iff_hasEffectiveEpi`: a sieve is a covering sieve for the regular topology if and only if it contains an effective epi. -/ namespace CategoryTheory.regularTopology open Limits variable {C : Type*} [Category C] [Preregular C] {X : C} /-- For a preregular category, any sieve that contains an `EffectiveEpi` is a covering sieve of the regular topology. Note: This is one direction of `mem_sieves_iff_hasEffectiveEpi`, but is needed for the proof. -/ theorem mem_sieves_of_hasEffectiveEpi (S : Sieve X) : (∃ (Y : C) (π : Y ⟶ X), EffectiveEpi π ∧ S.arrows π) → (S ∈ (regularTopology C) X) := by rintro ⟨Y, π, h⟩ have h_le : Sieve.generate (Presieve.ofArrows (fun () ↦ Y) (fun _ ↦ π)) ≤ S := by rw [Sieve.generate_le_iff (Presieve.ofArrows _ _) S] apply Presieve.le_of_factorsThru_sieve (Presieve.ofArrows _ _) S _ intro W g f refine ⟨W, 𝟙 W, ?_⟩ cases f exact ⟨π, ⟨h.2, Category.id_comp π⟩⟩ apply Coverage.saturate_of_superset (regularCoverage C) h_le exact Coverage.Saturate.of X _ ⟨Y, π, rfl, h.1⟩ /-- Effective epis in a preregular category are stable under composition. -/ instance {Y Y' : C} (π : Y ⟶ X) [EffectiveEpi π] (π' : Y' ⟶ Y) [EffectiveEpi π'] : EffectiveEpi (π' ≫ π) := by rw [effectiveEpi_iff_effectiveEpiFamily, ← Sieve.effectiveEpimorphic_family] suffices h₂ : (Sieve.generate (Presieve.ofArrows _ _)) ∈ (regularTopology C) X by change Nonempty _ rw [← Sieve.forallYonedaIsSheaf_iff_colimit] exact fun W => regularTopology.isSheaf_yoneda_obj W _ h₂ apply Coverage.Saturate.transitive X (Sieve.generate (Presieve.ofArrows (fun () ↦ Y) (fun () ↦ π))) · apply Coverage.Saturate.of use Y, π · intro V f ⟨Y₁, h, g, ⟨hY, hf⟩⟩ rw [← hf, Sieve.pullback_comp] apply (regularTopology C).pullback_stable' apply regularTopology.mem_sieves_of_hasEffectiveEpi cases hY exact ⟨Y', π', inferInstance, Y', (𝟙 _), π' ≫ π, Presieve.ofArrows.mk (), (by simp)⟩ /-- A sieve is a cover for the regular topology if and only if it contains an `EffectiveEpi`. -/ theorem mem_sieves_iff_hasEffectiveEpi (S : Sieve X) : (S ∈ (regularTopology C) X) ↔ ∃ (Y : C) (π : Y ⟶ X), EffectiveEpi π ∧ (S.arrows π) := by constructor · intro h induction h with | of Y T hS => rcases hS with ⟨Y', π, h'⟩ refine ⟨Y', π, h'.2, ?_⟩ rcases h' with ⟨rfl, _⟩ exact ⟨Y', 𝟙 Y', π, Presieve.ofArrows.mk (), (by simp)⟩ | top Y => exact ⟨Y, (𝟙 Y), inferInstance, by simp only [Sieve.top_apply]⟩ | transitive Y R S _ _ a b => rcases a with ⟨Y₁, π, ⟨h₁,h₂⟩⟩ choose Y' π' _ H using b h₂ exact ⟨Y', π' ≫ π, inferInstance, (by simpa using H)⟩ · exact regularTopology.mem_sieves_of_hasEffectiveEpi S end CategoryTheory.regularTopology
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/DenseSubsite/Basic.lean
import Mathlib.CategoryTheory.Sites.Sheaf import Mathlib.CategoryTheory.Sites.CoverLifting import Mathlib.CategoryTheory.Sites.CoverPreserving import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Sites.LocallyFullyFaithful /-! # Dense subsites We define `IsCoverDense` functors into sites as functors such that there exists a covering sieve that factors through images of the functor for each object in `D`. ## Main results - `CategoryTheory.Functor.IsCoverDense.Types.presheafHom`: If `G : C ⥤ (D, K)` is locally-full and cover-dense, then given any presheaf `ℱ` and sheaf `ℱ'` on `D`, and a morphism `α : G ⋙ ℱ ⟶ G ⋙ ℱ'`, we may glue them together to obtain a morphism of presheaves `ℱ ⟶ ℱ'`. - `CategoryTheory.Functor.IsCoverDense.sheafIso`: If `ℱ` above is a sheaf and `α` is an iso, then the result is also an iso. - `CategoryTheory.Functor.IsCoverDense.iso_of_restrict_iso`: If `G : C ⥤ (D, K)` is locally-full and cover-dense, then given any sheaves `ℱ, ℱ'` on `D`, and a morphism `α : ℱ ⟶ ℱ'`, then `α` is an iso if `G ⋙ ℱ ⟶ G ⋙ ℱ'` is iso. - `CategoryTheory.Functor.IsDenseSubsite`: The functor `G : C ⥤ D` exhibits `(C, J)` as a dense subsite of `(D, K)` if `G` is cover-dense, locally fully-faithful, and `S` is a cover of `C` iff the image of `S` in `D` is a cover. ## References * [Elephant]: *Sketches of an Elephant*, ℱ. T. Johnstone: C2.2. * https://ncatlab.org/nlab/show/dense+sub-site * https://ncatlab.org/nlab/show/comparison+lemma -/ universe w v u namespace CategoryTheory variable {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] variable (J : GrothendieckTopology C) (K : GrothendieckTopology D) variable {L : GrothendieckTopology E} /-- An auxiliary structure that witnesses the fact that `f` factors through an image object of `G`. -/ structure Presieve.CoverByImageStructure (G : C ⥤ D) {V U : D} (f : V ⟶ U) where obj : C lift : V ⟶ G.obj obj map : G.obj obj ⟶ U fac : lift ≫ map = f := by cat_disch attribute [nolint docBlame] Presieve.CoverByImageStructure.obj Presieve.CoverByImageStructure.lift Presieve.CoverByImageStructure.map Presieve.CoverByImageStructure.fac attribute [reassoc (attr := simp)] Presieve.CoverByImageStructure.fac /-- For a functor `G : C ⥤ D`, and an object `U : D`, `Presieve.coverByImage G U` is the presieve of `U` consisting of those arrows that factor through images of `G`. -/ def Presieve.coverByImage (G : C ⥤ D) (U : D) : Presieve U := fun _ f => Nonempty (Presieve.CoverByImageStructure G f) /-- For a functor `G : C ⥤ D`, and an object `U : D`, `Sieve.coverByImage G U` is the sieve of `U` consisting of those arrows that factor through images of `G`. -/ def Sieve.coverByImage (G : C ⥤ D) (U : D) : Sieve U := ⟨Presieve.coverByImage G U, fun ⟨⟨Z, f₁, f₂, (e : _ = _)⟩⟩ g => ⟨⟨Z, g ≫ f₁, f₂, show (g ≫ f₁) ≫ f₂ = g ≫ _ by rw [Category.assoc, ← e]⟩⟩⟩ theorem Presieve.in_coverByImage (G : C ⥤ D) {X : D} {Y : C} (f : G.obj Y ⟶ X) : Presieve.coverByImage G X f := ⟨⟨Y, 𝟙 _, f, by simp⟩⟩ /-- A functor `G : (C, J) ⥤ (D, K)` is cover dense if for each object in `D`, there exists a covering sieve in `D` that factors through images of `G`. This definition can be found in https://ncatlab.org/nlab/show/dense+sub-site Definition 2.2. -/ class Functor.IsCoverDense (G : C ⥤ D) (K : GrothendieckTopology D) : Prop where is_cover : ∀ U : D, Sieve.coverByImage G U ∈ K U lemma Functor.is_cover_of_isCoverDense (G : C ⥤ D) (K : GrothendieckTopology D) [G.IsCoverDense K] (U : D) : Sieve.coverByImage G U ∈ K U := by apply Functor.IsCoverDense.is_cover lemma Functor.isCoverDense_of_generate_singleton_functor_π_mem (G : C ⥤ D) (K : GrothendieckTopology D) (h : ∀ B, ∃ (X : C) (f : G.obj X ⟶ B), Sieve.generate (Presieve.singleton f) ∈ K B) : G.IsCoverDense K where is_cover B := by obtain ⟨X, f, h⟩ := h B refine K.superset_covering ?_ h intro Y f ⟨Z, g, _, h, w⟩ cases h exact ⟨⟨_, g, _, w⟩⟩ attribute [nolint docBlame] CategoryTheory.Functor.IsCoverDense.is_cover open Presieve Opposite namespace Functor namespace IsCoverDense variable {K} variable {A : Type*} [Category A] (G : C ⥤ D) -- this is not marked with `@[ext]` because `H` cannot be inferred from the type theorem ext [G.IsCoverDense K] (ℱ : Sheaf K (Type _)) (X : D) {s t : ℱ.val.obj (op X)} (h : ∀ ⦃Y : C⦄ (f : G.obj Y ⟶ X), ℱ.val.map f.op s = ℱ.val.map f.op t) : s = t := by apply ((isSheaf_iff_isSheaf_of_type _ _ ).1 ℱ.cond (Sieve.coverByImage G X) (G.is_cover_of_isCoverDense K X)).isSeparatedFor.ext rintro Y _ ⟨Z, f₁, f₂, ⟨rfl⟩⟩ simp [h f₂] variable {G} theorem functorPullback_pushforward_covering [G.IsCoverDense K] [G.IsLocallyFull K] {X : C} (T : K (G.obj X)) : (T.val.functorPullback G).functorPushforward G ∈ K (G.obj X) := by refine K.transitive T.2 _ fun Y iYX hiYX ↦ ?_ apply K.transitive (G.is_cover_of_isCoverDense _ _) _ rintro W _ ⟨Z, iWZ, iZY, rfl⟩ rw [Sieve.pullback_comp]; apply K.pullback_stable; clear W iWZ apply K.superset_covering ?_ (G.functorPushforward_imageSieve_mem _ (iZY ≫ iYX)) rintro W _ ⟨V, iVZ, iWV, ⟨iVX, e⟩, rfl⟩ exact ⟨_, iVX, iWV, by simpa [e] using T.1.downward_closed hiYX (G.map iVZ ≫ iZY), by simp [e]⟩ /-- (Implementation). Given a hom between the pullbacks of two sheaves, we can whisker it with `coyoneda` to obtain a hom between the pullbacks of the sheaves of maps from `X`. -/ @[simps!] def homOver {ℱ : Dᵒᵖ ⥤ A} {ℱ' : Sheaf K A} (α : G.op ⋙ ℱ ⟶ G.op ⋙ ℱ'.val) (X : A) : G.op ⋙ ℱ ⋙ coyoneda.obj (op X) ⟶ G.op ⋙ (sheafOver ℱ' X).val := whiskerRight α (coyoneda.obj (op X)) /-- (Implementation). Given an iso between the pullbacks of two sheaves, we can whisker it with `coyoneda` to obtain an iso between the pullbacks of the sheaves of maps from `X`. -/ @[simps!] def isoOver {ℱ ℱ' : Sheaf K A} (α : G.op ⋙ ℱ.val ≅ G.op ⋙ ℱ'.val) (X : A) : G.op ⋙ (sheafOver ℱ X).val ≅ G.op ⋙ (sheafOver ℱ' X).val := isoWhiskerRight α (coyoneda.obj (op X)) theorem sheaf_eq_amalgamation (ℱ : Sheaf K A) {X : A} {U : D} {T : Sieve U} (hT) (x : FamilyOfElements _ T) (hx) (t) (h : x.IsAmalgamation t) : t = (ℱ.cond X T hT).amalgamate x hx := (ℱ.cond X T hT).isSeparatedFor x t _ h ((ℱ.cond X T hT).isAmalgamation hx) namespace Types variable {ℱ : Dᵒᵖ ⥤ Type v} {ℱ' : Sheaf K (Type v)} (α : G.op ⋙ ℱ ⟶ G.op ⋙ ℱ'.val) theorem naturality_apply [G.IsLocallyFull K] {X Y : C} (i : G.obj X ⟶ G.obj Y) (x) : ℱ'.1.map i.op (α.app _ x) = α.app _ (ℱ.map i.op x) := by have {X Y} (i : X ⟶ Y) (x) : ℱ'.1.map (G.map i).op (α.app _ x) = α.app _ (ℱ.map (G.map i).op x) := by exact congr_fun (α.naturality i.op).symm x refine IsLocallyFull.ext G _ i fun V iVX iVY e ↦ ?_ simp only [← FunctorToTypes.map_comp_apply, ← op_comp, ← e, this] @[reassoc] theorem naturality [G.IsLocallyFull K] {X Y : C} (i : G.obj X ⟶ G.obj Y) : α.app _ ≫ ℱ'.1.map i.op = ℱ.map i.op ≫ α.app _ := types_ext _ _ (naturality_apply α i) /-- (Implementation). Given a section of `ℱ` on `X`, we can obtain a family of elements valued in `ℱ'` that is defined on a cover generated by the images of `G`. -/ noncomputable def pushforwardFamily {X} (x : ℱ.obj (op X)) : FamilyOfElements ℱ'.val (coverByImage G X) := fun _ _ hf => ℱ'.val.map hf.some.lift.op <| α.app (op _) (ℱ.map hf.some.map.op x) @[simp] theorem pushforwardFamily_def {X} (x : ℱ.obj (op X)) : pushforwardFamily α x = fun _ _ hf => ℱ'.val.map hf.some.lift.op <| α.app (op _) (ℱ.map hf.some.map.op x) := rfl @[simp] theorem pushforwardFamily_apply [G.IsLocallyFull K] {X} (x : ℱ.obj (op X)) {Y : C} (f : G.obj Y ⟶ X) : pushforwardFamily α x f (Presieve.in_coverByImage G f) = α.app (op Y) (ℱ.map f.op x) := by simp only [pushforwardFamily_def, op_obj] generalize Nonempty.some (Presieve.in_coverByImage G f) = l obtain ⟨W, iYW, iWX, rfl⟩ := l simp only [← op_comp, ← FunctorToTypes.map_comp_apply, naturality_apply] variable [G.IsCoverDense K] [G.IsLocallyFull K] /-- (Implementation). The `pushforwardFamily` defined is compatible. -/ theorem pushforwardFamily_compatible {X} (x : ℱ.obj (op X)) : (pushforwardFamily α x).Compatible := by suffices ∀ {Z W₁ W₂} (iWX₁ : G.obj W₁ ⟶ X) (iWX₂ : G.obj W₂ ⟶ X) (iZW₁ : Z ⟶ G.obj W₁) (iZW₂ : Z ⟶ G.obj W₂), iZW₁ ≫ iWX₁ = iZW₂ ≫ iWX₂ → ℱ'.1.map iZW₁.op (α.app _ (ℱ.map iWX₁.op x)) = ℱ'.1.map iZW₂.op (α.app _ (ℱ.map iWX₂.op x)) by rintro Y₁ Y₂ Z iZY₁ iZY₂ f₁ f₂ h₁ h₂ e simp only [pushforwardFamily, ← FunctorToTypes.map_comp_apply, ← op_comp] generalize Nonempty.some h₁ = l₁ generalize Nonempty.some h₂ = l₂ obtain ⟨W₁, iYW₁, iWX₁, rfl⟩ := l₁ obtain ⟨W₂, iYW₂, iWX₂, rfl⟩ := l₂ exact this _ _ _ _ (by simpa only [Category.assoc] using e) introv e refine ext G _ _ fun V iVZ ↦ ?_ simp only [← op_comp, ← FunctorToTypes.map_comp_apply, naturality_apply, Category.assoc, e] /-- (Implementation). The morphism `ℱ(X) ⟶ ℱ'(X)` given by gluing the `pushforwardFamily`. -/ noncomputable def appHom (X : D) : ℱ.obj (op X) ⟶ ℱ'.val.obj (op X) := fun x => ((isSheaf_iff_isSheaf_of_type _ _ ).1 ℱ'.cond _ (G.is_cover_of_isCoverDense _ X)).amalgamate (pushforwardFamily α x) (pushforwardFamily_compatible α x) @[simp] theorem appHom_restrict {X : D} {Y : C} (f : op X ⟶ op (G.obj Y)) (x) : ℱ'.val.map f (appHom α X x) = α.app (op Y) (ℱ.map f x) := (((isSheaf_iff_isSheaf_of_type _ _ ).1 ℱ'.cond _ (G.is_cover_of_isCoverDense _ X)).valid_glue (pushforwardFamily_compatible α x) f.unop (Presieve.in_coverByImage G f.unop)).trans (pushforwardFamily_apply _ _ _) @[simp] theorem appHom_valid_glue {X : D} {Y : C} (f : op X ⟶ op (G.obj Y)) : appHom α X ≫ ℱ'.val.map f = ℱ.map f ≫ α.app (op Y) := by ext apply appHom_restrict /-- (Implementation). The maps given in `appIso` is inverse to each other and gives a `ℱ(X) ≅ ℱ'(X)`. -/ @[simps] noncomputable def appIso {ℱ ℱ' : Sheaf K (Type v)} (i : G.op ⋙ ℱ.val ≅ G.op ⋙ ℱ'.val) (X : D) : ℱ.val.obj (op X) ≅ ℱ'.val.obj (op X) where hom := appHom i.hom X inv := appHom i.inv X hom_inv_id := by ext x apply Functor.IsCoverDense.ext G intro Y f simp inv_hom_id := by ext x apply Functor.IsCoverDense.ext G intro Y f simp /-- Given a natural transformation `G ⋙ ℱ ⟶ G ⋙ ℱ'` between presheaves of types, where `G` is locally-full and cover-dense, and `ℱ'` is a sheaf, we may obtain a natural transformation between sheaves. -/ @[simps] noncomputable def presheafHom (α : G.op ⋙ ℱ ⟶ G.op ⋙ ℱ'.val) : ℱ ⟶ ℱ'.val where app X := appHom α (unop X) naturality X Y f := by ext x apply Functor.IsCoverDense.ext G intro Y' f' simp only [appHom_restrict, types_comp_apply, ← FunctorToTypes.map_comp_apply] /-- Given a natural isomorphism `G ⋙ ℱ ≅ G ⋙ ℱ'` between presheaves of types, where `G` is locally-full and cover-dense, and `ℱ, ℱ'` are sheaves, we may obtain a natural isomorphism between presheaves. -/ @[simps!] noncomputable def presheafIso {ℱ ℱ' : Sheaf K (Type v)} (i : G.op ⋙ ℱ.val ≅ G.op ⋙ ℱ'.val) : ℱ.val ≅ ℱ'.val := NatIso.ofComponents (fun X => appIso i (unop X)) @(presheafHom i.hom).naturality /-- Given a natural isomorphism `G ⋙ ℱ ≅ G ⋙ ℱ'` between presheaves of types, where `G` is locally-full and cover-dense, and `ℱ, ℱ'` are sheaves, we may obtain a natural isomorphism between sheaves. -/ @[simps] noncomputable def sheafIso {ℱ ℱ' : Sheaf K (Type v)} (i : G.op ⋙ ℱ.val ≅ G.op ⋙ ℱ'.val) : ℱ ≅ ℱ' where hom := ⟨(presheafIso i).hom⟩ inv := ⟨(presheafIso i).inv⟩ hom_inv_id := by ext1 apply (presheafIso i).hom_inv_id inv_hom_id := by ext1 apply (presheafIso i).inv_hom_id end Types open Types variable [G.IsCoverDense K] [G.IsLocallyFull K] {ℱ : Dᵒᵖ ⥤ A} {ℱ' : Sheaf K A} /-- (Implementation). The sheaf map given in `types.sheaf_hom` is natural in terms of `X`. -/ @[simps] noncomputable def sheafCoyonedaHom (α : G.op ⋙ ℱ ⟶ G.op ⋙ ℱ'.val) : coyoneda ⋙ (whiskeringLeft Dᵒᵖ A (Type _)).obj ℱ ⟶ coyoneda ⋙ (whiskeringLeft Dᵒᵖ A (Type _)).obj ℱ'.val where app X := presheafHom (homOver α (unop X)) naturality X Y f := by ext U x change appHom (homOver α (unop Y)) (unop U) (f.unop ≫ x) = f.unop ≫ appHom (homOver α (unop X)) (unop U) x symm apply sheaf_eq_amalgamation · apply G.is_cover_of_isCoverDense -- Porting note: the following line closes a goal which didn't exist before reenableeta · exact pushforwardFamily_compatible (homOver α Y.unop) (f.unop ≫ x) intro Y' f' hf' change unop X ⟶ ℱ.obj (op (unop _)) at x dsimp simp only [Category.assoc] congr 1 conv_lhs => rw [← hf'.some.fac] simp only [← Category.assoc, op_comp, Functor.map_comp] congr 1 exact (appHom_restrict (homOver α (unop X)) hf'.some.map.op x).trans (by simp) /-- (Implementation). `sheafCoyonedaHom` but the order of the arguments of the functor are swapped. -/ noncomputable def sheafYonedaHom (α : G.op ⋙ ℱ ⟶ G.op ⋙ ℱ'.val) : ℱ ⋙ yoneda ⟶ ℱ'.val ⋙ yoneda where app U := let α := (sheafCoyonedaHom α) { app := fun X => (α.app X).app U naturality := fun X Y f => by simpa using congr_app (α.naturality f) U } naturality U V i := by ext X x exact congr_fun (((sheafCoyonedaHom α).app X).naturality i) x /-- Given a natural transformation `G ⋙ ℱ ⟶ G ⋙ ℱ'` between presheaves of arbitrary category, where `G` is locally-full and cover-dense, and `ℱ'` is a sheaf, we may obtain a natural transformation between presheaves. -/ noncomputable def sheafHom (α : G.op ⋙ ℱ ⟶ G.op ⋙ ℱ'.val) : ℱ ⟶ ℱ'.val := let α' := sheafYonedaHom α { app := fun X => yoneda.preimage (α'.app X) naturality := fun X Y f => yoneda.map_injective (by simpa using α'.naturality f) } /-- Given a natural isomorphism `G ⋙ ℱ ≅ G ⋙ ℱ'` between presheaves of arbitrary category, where `G` is locally-full and cover-dense, and `ℱ', ℱ` are sheaves, we may obtain a natural isomorphism between presheaves. -/ @[simps!] noncomputable def presheafIso {ℱ ℱ' : Sheaf K A} (i : G.op ⋙ ℱ.val ≅ G.op ⋙ ℱ'.val) : ℱ.val ≅ ℱ'.val := by have : ∀ X : Dᵒᵖ, IsIso ((sheafHom i.hom).app X) := by intro X rw [← isIso_iff_of_reflects_iso _ yoneda] use (sheafYonedaHom i.inv).app X constructor <;> ext x : 2 <;> simp only [sheafHom, NatTrans.comp_app, NatTrans.id_app, Functor.map_preimage] · exact ((Types.presheafIso (isoOver i (unop x))).app X).hom_inv_id · exact ((Types.presheafIso (isoOver i (unop x))).app X).inv_hom_id haveI : IsIso (sheafHom i.hom) := by apply NatIso.isIso_of_isIso_app apply asIso (sheafHom i.hom) /-- Given a natural isomorphism `G ⋙ ℱ ≅ G ⋙ ℱ'` between presheaves of arbitrary category, where `G` is locally-full and cover-dense, and `ℱ', ℱ` are sheaves, we may obtain a natural isomorphism between presheaves. -/ @[simps] noncomputable def sheafIso {ℱ ℱ' : Sheaf K A} (i : G.op ⋙ ℱ.val ≅ G.op ⋙ ℱ'.val) : ℱ ≅ ℱ' where hom := ⟨(presheafIso i).hom⟩ inv := ⟨(presheafIso i).inv⟩ hom_inv_id := by ext1 apply (presheafIso i).hom_inv_id inv_hom_id := by ext1 apply (presheafIso i).inv_hom_id /-- The constructed `sheafHom α` is equal to `α` when restricted onto `C`. -/ theorem sheafHom_restrict_eq (α : G.op ⋙ ℱ ⟶ G.op ⋙ ℱ'.val) : whiskerLeft G.op (sheafHom α) = α := by ext X apply yoneda.map_injective ext U erw [yoneda.map_preimage] symm change (show (ℱ'.val ⋙ coyoneda.obj (op (unop U))).obj (op (G.obj (unop X))) from _) = _ apply sheaf_eq_amalgamation ℱ' (G.is_cover_of_isCoverDense _ _) -- Porting note: next line was not needed in mathlib3 · exact (pushforwardFamily_compatible _ _) intro Y f hf conv_lhs => rw [← hf.some.fac] simp only [pushforwardFamily, Functor.comp_map, yoneda_map_app, flip_obj_map, op_comp, FunctorToTypes.map_comp_apply, homOver_app] congr 1 simp only [Category.assoc] congr 1 have := naturality_apply (G := G) (ℱ := ℱ ⋙ coyoneda.obj (op <| (G.op ⋙ ℱ).obj X)) (ℱ' := ⟨_, Presheaf.isSheaf_comp_of_isSheaf K ℱ'.val (coyoneda.obj (op ((G.op ⋙ ℱ).obj X))) ℱ'.cond⟩) (whiskerRight α (coyoneda.obj _)) hf.some.map (𝟙 _) simpa using this variable (G) in /-- If the pullback map is obtained via whiskering, then the result `sheaf_hom (whisker_left G.op α)` is equal to `α`. -/ theorem sheafHom_eq (α : ℱ ⟶ ℱ'.val) : sheafHom (whiskerLeft G.op α) = α := by ext X apply yoneda.map_injective ext U erw [yoneda.map_preimage] symm change (show (ℱ'.val ⋙ coyoneda.obj (op (unop U))).obj (op (unop X)) from _) = _ apply sheaf_eq_amalgamation ℱ' (G.is_cover_of_isCoverDense _ _) -- Porting note: next line was not needed in mathlib3 · exact (pushforwardFamily_compatible _ _) intro Y f hf conv_lhs => rw [← hf.some.fac] dsimp; simp /-- A locally-full and cover-dense functor `G` induces an equivalence between morphisms into a sheaf and morphisms over the restrictions via `G`. -/ noncomputable def restrictHomEquivHom : (G.op ⋙ ℱ ⟶ G.op ⋙ ℱ'.val) ≃ (ℱ ⟶ ℱ'.val) where toFun := sheafHom invFun := whiskerLeft G.op left_inv := sheafHom_restrict_eq right_inv := sheafHom_eq _ /-- Given a locally-full and cover-dense functor `G` and a natural transformation of sheaves `α : ℱ ⟶ ℱ'`, if the pullback of `α` along `G` is iso, then `α` is also iso. -/ theorem iso_of_restrict_iso {ℱ ℱ' : Sheaf K A} (α : ℱ ⟶ ℱ') (i : IsIso (whiskerLeft G.op α.val)) : IsIso α := by convert (sheafIso (asIso (whiskerLeft G.op α.val))).isIso_hom using 1 ext1 apply (sheafHom_eq _ _).symm variable (G K) /-- A locally-fully-faithful and cover-dense functor preserves compatible families. -/ lemma compatiblePreserving [G.IsLocallyFaithful K] : CompatiblePreserving K G := by constructor intro ℱ Z T x hx Y₁ Y₂ X f₁ f₂ g₁ g₂ hg₁ hg₂ eq apply Functor.IsCoverDense.ext G intro W i refine IsLocallyFull.ext G _ (i ≫ f₁) fun V₁ iVW iV₁Y₁ e₁ ↦ ?_ refine IsLocallyFull.ext G _ (G.map iVW ≫ i ≫ f₂) fun V₂ iV₂V₁ iV₂Y₂ e₂ ↦ ?_ refine IsLocallyFaithful.ext G _ (iV₂V₁ ≫ iV₁Y₁ ≫ g₁) (iV₂Y₂ ≫ g₂) (by simp [e₁, e₂, eq]) ?_ intro V₃ iV₃ e₄ simp only [← op_comp, ← FunctorToTypes.map_comp_apply, ← e₁, ← e₂, ← Functor.map_comp] apply hx simpa using e₄ lemma isContinuous [G.IsLocallyFaithful K] (Hp : CoverPreserving J K G) : G.IsContinuous J K := isContinuous_of_coverPreserving (compatiblePreserving K G) Hp instance full_sheafPushforwardContinuous [G.IsContinuous J K] : Full (G.sheafPushforwardContinuous A J K) where map_surjective α := ⟨⟨sheafHom α.val⟩, Sheaf.Hom.ext <| sheafHom_restrict_eq α.val⟩ instance faithful_sheafPushforwardContinuous [G.IsContinuous J K] : Faithful (G.sheafPushforwardContinuous A J K) where map_injective := by intro ℱ ℱ' α β e ext1 apply_fun fun e => e.val at e dsimp [sheafPushforwardContinuous] at e rw [← sheafHom_eq G α.val, ← sheafHom_eq G β.val, e] end IsCoverDense /-- If `G : C ⥤ D` is cover dense and full, then the map `(P ⟶ Q) → (G.op ⋙ P ⟶ G.op ⋙ Q)` is bijective when `Q` is a sheaf. -/ lemma whiskerLeft_obj_map_bijective_of_isCoverDense (G : C ⥤ D) [G.IsCoverDense K] [G.IsLocallyFull K] {A : Type*} [Category A] (P Q : Dᵒᵖ ⥤ A) (hQ : Presheaf.IsSheaf K Q) : Function.Bijective (((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).map : (P ⟶ Q) → _) := (IsCoverDense.restrictHomEquivHom (ℱ' := ⟨Q, hQ⟩)).symm.bijective variable {A : Type*} [Category A] (G : C ⥤ D) /-- The functor `G : C ⥤ D` exhibits `(C, J)` as a dense subsite of `(D, K)` if `G` is cover-dense, locally fully-faithful, and `S` is a cover of `C` if and only if the image of `S` in `D` is a cover. -/ class IsDenseSubsite : Prop where isCoverDense' : G.IsCoverDense K := by infer_instance isLocallyFull' : G.IsLocallyFull K := by infer_instance isLocallyFaithful' : G.IsLocallyFaithful K := by infer_instance functorPushforward_mem_iff : ∀ {X : C} {S : Sieve X}, S.functorPushforward G ∈ K _ ↔ S ∈ J _ lemma functorPushforward_mem_iff {X : C} {S : Sieve X} [G.IsDenseSubsite J K] : S.functorPushforward G ∈ K _ ↔ S ∈ J _ := IsDenseSubsite.functorPushforward_mem_iff namespace IsDenseSubsite variable [G.IsDenseSubsite J K] include J K lemma isCoverDense : G.IsCoverDense K := isCoverDense' J lemma isLocallyFull : G.IsLocallyFull K := isLocallyFull' J lemma isLocallyFaithful : G.IsLocallyFaithful K := isLocallyFaithful' J lemma coverPreserving : CoverPreserving J K G := ⟨functorPushforward_mem_iff.mpr⟩ instance (priority := 900) : G.IsContinuous J K := letI := IsDenseSubsite.isCoverDense J K G letI := IsDenseSubsite.isLocallyFull J K G letI := IsDenseSubsite.isLocallyFaithful J K G IsCoverDense.isContinuous J K G (IsDenseSubsite.coverPreserving J K G) instance (priority := 900) : G.IsCocontinuous J K where cover_lift hS := letI := IsDenseSubsite.isCoverDense J K G letI := IsDenseSubsite.isLocallyFull J K G IsDenseSubsite.functorPushforward_mem_iff.mp (IsCoverDense.functorPullback_pushforward_covering ⟨_, hS⟩) instance full_sheafPushforwardContinuous : Full (G.sheafPushforwardContinuous A J K) := letI := IsDenseSubsite.isCoverDense J K G letI := IsDenseSubsite.isLocallyFull J K G inferInstance instance faithful_sheafPushforwardContinuous : Faithful (G.sheafPushforwardContinuous A J K) := letI := IsDenseSubsite.isCoverDense J K G letI := IsDenseSubsite.isLocallyFull J K G inferInstance lemma imageSieve_mem {U V} (f : G.obj U ⟶ G.obj V) : G.imageSieve f ∈ J _ := letI := IsDenseSubsite.isLocallyFull J K G IsDenseSubsite.functorPushforward_mem_iff.mp (G.functorPushforward_imageSieve_mem K f) lemma equalizer_mem {U V} (f₁ f₂ : U ⟶ V) (e : G.map f₁ = G.map f₂) : Sieve.equalizer f₁ f₂ ∈ J _ := letI := IsDenseSubsite.isLocallyFaithful J K G IsDenseSubsite.functorPushforward_mem_iff.mp (G.functorPushforward_equalizer_mem K f₁ f₂ e) end IsDenseSubsite end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/DenseSubsite/SheafEquiv.lean
import Mathlib.CategoryTheory.Sites.DenseSubsite.Basic /-! # The equivalence of categories of sheaves of a dense subsite - `CategoryTheory.Functor.IsDenseSubsite.sheafEquiv`: If `G : C ⥤ D` exhibits `(C, J)` as a dense subsite of `(D, K)`, it induces an equivalence of category of sheaves valued in a category with suitable limits. ## References * [Elephant]: *Sketches of an Elephant*, ℱ. T. Johnstone: C2.2. * https://ncatlab.org/nlab/show/dense+sub-site * https://ncatlab.org/nlab/show/comparison+lemma -/ universe w v u w' namespace CategoryTheory.Functor.IsDenseSubsite open CategoryTheory Opposite variable {C D : Type*} [Category C] [Category D] variable (G : C ⥤ D) variable (J : GrothendieckTopology C) (K : GrothendieckTopology D) variable {A : Type w} [Category.{w'} A] [∀ X, Limits.HasLimitsOfShape (StructuredArrow X G.op) A] variable [G.IsDenseSubsite J K] include K in lemma isIso_ranCounit_app_of_isDenseSubsite (Y : Sheaf J A) (U X) : IsIso ((yoneda.map ((G.op.ranCounit.app Y.val).app (op U))).app (op X)) := by rw [isIso_iff_bijective] constructor · intro f₁ f₂ e apply (isPointwiseRightKanExtensionRanCounit G.op Y.1 (.op (G.obj U))).hom_ext rintro ⟨⟨⟨⟩⟩, ⟨W⟩, g⟩ obtain ⟨g, rfl⟩ : ∃ g' : G.obj W ⟶ G.obj U, g = g'.op := ⟨g.unop, rfl⟩ apply (Y.2 X _ (IsDenseSubsite.imageSieve_mem J K G g)).isSeparatedFor.ext dsimp rintro V iVW ⟨iVU, e'⟩ have := congr($e ≫ Y.1.map iVU.op) simp only [comp_obj, yoneda_map_app, Category.assoc, comp_map, ← NatTrans.naturality, op_obj, op_map, Quiver.Hom.unop_op, ← map_comp_assoc, ← op_comp, ← e'] at this ⊢ erw [← NatTrans.naturality] at this exact this · intro f have (X Y Z) (f : X ⟶ Y) (g : G.obj Y ⟶ G.obj Z) (hf : G.imageSieve g f) : Exists _ := hf choose l hl using this let c : Limits.Cone (StructuredArrow.proj (op (G.obj U)) G.op ⋙ Y.val) := by refine ⟨X, ⟨fun g ↦ ?_, ?_⟩⟩ · refine Y.2.amalgamate ⟨_, IsDenseSubsite.imageSieve_mem J K G g.hom.unop⟩ (fun I ↦ f ≫ Y.1.map (l _ _ _ _ _ I.hf).op) fun I₁ I₂ r ↦ ?_ apply (Y.2 X _ (IsDenseSubsite.equalizer_mem J K G (r.g₁ ≫ l _ _ _ _ _ I₁.hf) (r.g₂ ≫ l _ _ _ _ _ I₂.hf) ?_)).isSeparatedFor.ext fun V iUV (hiUV : _ = _) ↦ ?_ · simp only [const_obj_obj, op_obj, map_comp, hl] simp only [← map_comp_assoc, r.w] · simp [← map_comp, ← op_comp, hiUV] · dsimp rintro ⟨⟨⟨⟩⟩, ⟨W₁⟩, g₁⟩ ⟨⟨⟨⟩⟩, ⟨W₂⟩, g₂⟩ ⟨⟨⟨⟨⟩⟩⟩, i, hi⟩ dsimp at g₁ g₂ i hi -- See issue https://github.com/leanprover-community/mathlib4/pull/15781 for tracking performance regressions of `rintro` as here have h : g₂ = g₁ ≫ (G.map i.unop).op := by simpa only [Category.id_comp] using hi rcases h with ⟨rfl⟩ have h : ∃ g' : G.obj W₁ ⟶ G.obj U, g₁ = g'.op := ⟨g₁.unop, rfl⟩ rcases h with ⟨g, rfl⟩ have h : ∃ i' : W₂ ⟶ W₁, i = i'.op := ⟨i.unop, rfl⟩ rcases h with ⟨i, rfl⟩ simp only [unop_comp, Quiver.Hom.unop_op, Category.id_comp] apply Y.2.hom_ext ⟨_, IsDenseSubsite.imageSieve_mem J K G (G.map i ≫ g)⟩ intro I simp only [Presheaf.IsSheaf.amalgamate_map, Category.assoc, ← Functor.map_comp, ← op_comp] let I' : GrothendieckTopology.Cover.Arrow ⟨_, IsDenseSubsite.imageSieve_mem J K G g⟩ := ⟨_, I.f ≫ i, ⟨l _ _ _ _ _ I.hf, by simp [hl]⟩⟩ refine Eq.trans ?_ (Y.2.amalgamate_map _ _ _ I').symm apply (Y.2 X _ (IsDenseSubsite.equalizer_mem J K G (l _ _ _ _ _ I.hf) (l _ _ _ _ _ I'.hf) (by simp [I', hl]))).isSeparatedFor.ext fun V iUV (hiUV : _ = _) ↦ ?_ simp [I', ← Functor.map_comp, ← op_comp, hiUV] refine ⟨(isPointwiseRightKanExtensionRanCounit G.op Y.1 (.op (G.obj U))).lift c, ?_⟩ · have := (isPointwiseRightKanExtensionRanCounit G.op Y.1 (.op (G.obj U))).fac c (.mk (𝟙 _)) simp only [id_obj, comp_obj, StructuredArrow.proj_obj, StructuredArrow.mk_right, RightExtension.coneAt_pt, RightExtension.mk_left, RightExtension.coneAt_π_app, const_obj_obj, op_obj, StructuredArrow.mk_hom_eq_self, map_id, whiskeringLeft_obj_obj, RightExtension.mk_hom, Category.id_comp] at this simp only [c, id_obj, yoneda_map_app, this] apply Y.2.hom_ext ⟨_, IsDenseSubsite.imageSieve_mem J K G (𝟙 (G.obj U))⟩ _ _ fun I ↦ ?_ apply (Y.2 X _ (IsDenseSubsite.equalizer_mem J K G (l _ _ _ _ _ I.hf) I.f (by simp [hl]))).isSeparatedFor.ext fun V iUV (hiUV : _ = _) ↦ ?_ simp [← Functor.map_comp, ← op_comp, hiUV] instance (Y : Sheaf J A) : IsIso ((G.sheafAdjunctionCocontinuous A J K).counit.app Y) := by apply (config := { allowSynthFailures := true }) ReflectsIsomorphisms.reflects (sheafToPresheaf J A) rw [NatTrans.isIso_iff_isIso_app] intro ⟨U⟩ apply (config := { allowSynthFailures := true }) ReflectsIsomorphisms.reflects yoneda rw [NatTrans.isIso_iff_isIso_app] intro ⟨X⟩ simp only [comp_obj, sheafToPresheaf_obj, sheafPushforwardContinuous_obj_val_obj, yoneda_obj_obj, id_obj, sheafToPresheaf_map, sheafAdjunctionCocontinuous_counit_app_val, ranAdjunction_counit] exact isIso_ranCounit_app_of_isDenseSubsite G J K Y U X variable (A) /-- If `G : C ⥤ D` exhibits `(C, J)` as a dense subsite of `(D, K)`, it induces an equivalence of category of sheaves valued in a category with suitable limits. -/ @[simps! functor inverse] noncomputable def sheafEquiv : Sheaf J A ≌ Sheaf K A := (G.sheafAdjunctionCocontinuous A J K).toEquivalence.symm instance : (G.sheafPushforwardContinuous A J K).IsEquivalence := inferInstanceAs (IsDenseSubsite.sheafEquiv G _ _ _).inverse.IsEquivalence variable [HasWeakSheafify J A] [HasWeakSheafify K A] /-- The natural isomorphism exhibiting the compatibility of `IsDenseSubsite.sheafEquiv` with sheafification. -/ noncomputable abbrev sheafEquivSheafificationCompatibility : (whiskeringLeft _ _ A).obj G.op ⋙ presheafToSheaf _ _ ≅ presheafToSheaf _ _ ⋙ (sheafEquiv G J K A).inverse := by apply Functor.pushforwardContinuousSheafificationCompatibility end IsDenseSubsite end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/DenseSubsite/InducedTopology.lean
import Mathlib.CategoryTheory.Sites.DenseSubsite.SheafEquiv /-! # Induced Topology We say that a functor `G : C ⥤ (D, K)` is locally dense if for each covering sieve `T` in `D` of some `X : C`, `T ∩ mor(C)` generates a covering sieve of `X` in `D`. A locally dense fully faithful functor then induces a topology on `C` via `{ T ∩ mor(C) | T ∈ K }`. Note that this is equal to the collection of sieves on `C` whose image generates a covering sieve. This construction would make `C` both cover-lifting and cover-preserving. Some typical examples are full and cover-dense functors (for example the functor from a basis of a topological space `X` into `Opens X`). The functor `Over X ⥤ C` is also locally dense, and the induced topology can then be used to construct the big sites associated to a scheme. Given a fully faithful cover-dense functor `G : C ⥤ (D, K)` between small sites, we then have `Sheaf (H.inducedTopology) A ≌ Sheaf K A`. This is known as the comparison lemma. ## References * [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.2. * https://ncatlab.org/nlab/show/dense+sub-site * https://ncatlab.org/nlab/show/comparison+lemma -/ namespace CategoryTheory universe v u open Limits Opposite Presieve CategoryTheory variable {C : Type*} [Category C] {D : Type*} [Category D] (G : C ⥤ D) variable {J : GrothendieckTopology C} (K : GrothendieckTopology D) variable (A : Type v) [Category.{u} A] namespace Functor -- variables (A) [full G] [faithful G] /-- We say that a functor `C ⥤ D` into a site is "locally dense" if for each covering sieve `T` in `D`, `T ∩ mor(C)` generates a covering sieve in `D`. -/ class LocallyCoverDense : Prop where functorPushforward_functorPullback_mem : ∀ ⦃X : C⦄ (T : K (G.obj X)), (T.val.functorPullback G).functorPushforward G ∈ K (G.obj X) variable [G.LocallyCoverDense K] theorem pushforward_cover_iff_cover_pullback [G.Full] [G.Faithful] {X : C} (S : Sieve X) : K _ (S.functorPushforward G) ↔ ∃ T : K (G.obj X), T.val.functorPullback G = S := by constructor · intro hS exact ⟨⟨_, hS⟩, (Sieve.fullyFaithfulFunctorGaloisCoinsertion G X).u_l_eq S⟩ · rintro ⟨T, rfl⟩ exact LocallyCoverDense.functorPushforward_functorPullback_mem T variable [G.IsLocallyFull K] [G.IsLocallyFaithful K] /-- If a functor `G : C ⥤ (D, K)` is fully faithful and locally dense, then the set `{ T ∩ mor(C) | T ∈ K }` is a Grothendieck topology of `C`. -/ @[simps] def inducedTopology : GrothendieckTopology C where sieves _ S := K _ (S.functorPushforward G) top_mem' X := by change K _ _ rw [Sieve.functorPushforward_top] exact K.top_mem _ pullback_stable' X Y S iYX hS := by apply K.transitive (LocallyCoverDense.functorPushforward_functorPullback_mem ⟨_, K.pullback_stable (G.map iYX) hS⟩) rintro Z _ ⟨U, iUY, iZU, ⟨W, iWX, iUW, hiWX, e₁⟩, rfl⟩ rw [Sieve.pullback_comp] apply K.pullback_stable clear iZU Z apply K.transitive (G.functorPushforward_imageSieve_mem _ iUW) rintro Z _ ⟨U₁, iU₁U, iZU₁, ⟨iU₁W, e₂⟩, rfl⟩ rw [Sieve.pullback_comp] apply K.pullback_stable clear iZU₁ Z apply K.superset_covering ?_ (G.functorPushforward_equalizer_mem _ (iU₁U ≫ iUY ≫ iYX) (iU₁W ≫ iWX) (by simp [e₁, e₂])) rintro Z _ ⟨U₂, iU₂U₁, iZU₂, e₃ : _ = _, rfl⟩ refine ⟨_, iU₂U₁ ≫ iU₁U ≫ iUY, iZU₂, ?_, by simp⟩ simpa [e₃] using S.downward_closed hiWX (iU₂U₁ ≫ iU₁W) transitive' X S hS S' H' := by apply K.transitive hS rintro Y _ ⟨Z, g, i, hg, rfl⟩ rw [Sieve.pullback_comp] apply K.pullback_stable i refine K.superset_covering ?_ (H' hg) rintro W _ ⟨Z', g', i', hg, rfl⟩ refine ⟨Z', g' ≫ g, i', hg, ?_⟩ simp @[simp] lemma mem_inducedTopology_sieves_iff {X : C} (S : Sieve X) : S ∈ (G.inducedTopology K) X ↔ (S.functorPushforward G) ∈ K (G.obj X) := Iff.rfl /-- `G` is cover-lifting w.r.t. the induced topology. -/ instance inducedTopology_isCocontinuous : G.IsCocontinuous (G.inducedTopology K) K := ⟨@fun _ S hS => LocallyCoverDense.functorPushforward_functorPullback_mem ⟨S, hS⟩⟩ /-- `G` is cover-preserving w.r.t. the induced topology. -/ theorem inducedTopology_coverPreserving : CoverPreserving (G.inducedTopology K) K G := ⟨@fun _ _ hS => hS⟩ instance (priority := 900) locallyCoverDense_of_isCoverDense [G.IsCoverDense K] : G.LocallyCoverDense K where functorPushforward_functorPullback_mem _ _ := IsCoverDense.functorPullback_pushforward_covering _ instance (priority := 900) [G.IsCoverDense K] : G.IsDenseSubsite (G.inducedTopology K) K where functorPushforward_mem_iff := Iff.rfl variable (J) instance over_forget_locallyCoverDense (X : C) : (Over.forget X).LocallyCoverDense J where functorPushforward_functorPullback_mem Y T := by convert T.property ext Z f constructor · rintro ⟨_, _, g', hg, rfl⟩ exact T.val.downward_closed hg g' · intro hf exact ⟨Over.mk (f ≫ Y.hom), Over.homMk f, 𝟙 _, hf, (Category.id_comp _).symm⟩ /-- Cover-dense functors induces an equivalence of categories of sheaves. This is known as the comparison lemma. It requires that the sites are small and the value category is complete. -/ noncomputable def sheafInducedTopologyEquivOfIsCoverDense [G.IsCoverDense K] [∀ (X : Dᵒᵖ), HasLimitsOfShape (StructuredArrow X G.op) A] : Sheaf (G.inducedTopology K) A ≌ Sheaf K A := Functor.IsDenseSubsite.sheafEquiv G (G.inducedTopology K) K A end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/SheafCohomology/Basic.lean
import Mathlib.Algebra.Category.Grp.Abelian import Mathlib.Algebra.Category.Grp.Adjunctions import Mathlib.Algebra.Homology.DerivedCategory.Ext.Basic import Mathlib.CategoryTheory.Sites.Abelian import Mathlib.CategoryTheory.Sites.ConstantSheaf /-! # Sheaf cohomology Let `C` be a category equipped with a Grothendieck topology `J`. We define the cohomology types `Sheaf.H F n` of an abelian sheaf `F` on the site `(C, J)` for all `n : ℕ`. These abelian groups are defined as the `Ext`-groups from the constant abelian sheaf with values `ℤ` (actually `ULift ℤ`) to `F`. We also define `Sheaf.cohomologyPresheaf F n : Cᵒᵖ ⥤ AddCommGrpCat` which is the presheaf which sends `U` to the `n`th `Ext`-group from the free abelian sheaf generated by the presheaf of sets `yoneda.obj U` to `F`. ## TODO * if `U` is a terminal object of `C`, define an isomorphism `(F.cohomologyPresheaf n).obj (Opposite.op U) ≃+ Sheaf.H F n`. * if `U : C`, define an isomorphism `(F.cohomologyPresheaf n).obj (Opposite.op U) ≃+ Sheaf.H (F.over U) n`. -/ assert_not_exists TwoSidedIdeal universe w' w v u namespace CategoryTheory open Abelian variable {C : Type u} [Category.{v} C] {J : GrothendieckTopology C} namespace Sheaf section variable (F : Sheaf J AddCommGrpCat.{w}) [HasSheafify J AddCommGrpCat.{w}] [HasExt.{w'} (Sheaf J AddCommGrpCat.{w})] /-- The cohomology of an abelian sheaf in degree `n`. -/ def H (n : ℕ) : Type w' := Ext ((constantSheaf J AddCommGrpCat.{w}).obj (AddCommGrpCat.of (ULift ℤ))) F n noncomputable instance (n : ℕ) : AddCommGroup (F.H n) := by dsimp only [H] infer_instance end section variable [HasSheafify J AddCommGrpCat.{v}] [HasExt.{w'} (Sheaf J AddCommGrpCat.{v})] variable (J) in /-- The bifunctor which sends an abelian sheaf `F` and an object `U` to the `n`th Ext-group from the free abelian sheaf generated by the presheaf of sets `yoneda.obj U` to `F`. -/ noncomputable def cohomologyPresheafFunctor (n : ℕ) : Sheaf J AddCommGrpCat.{v} ⥤ Cᵒᵖ ⥤ AddCommGrpCat.{w'} := Functor.flip (Functor.op (yoneda ⋙ (Functor.whiskeringRight _ _ _).obj AddCommGrpCat.free ⋙ presheafToSheaf _ _) ⋙ extFunctor n) /-- Given an abelian sheaf `F`, this is the presheaf which sends `U` to the `n`th Ext-group from the free abelian sheaf generated by the presheaf of sets `yoneda.obj U` to `F`. -/ noncomputable abbrev cohomologyPresheaf (F : Sheaf J AddCommGrpCat.{v}) (n : ℕ) : Cᵒᵖ ⥤ AddCommGrpCat.{w'} := (cohomologyPresheafFunctor J n).obj F end end Sheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Descent/IsPrestack.lean
import Mathlib.CategoryTheory.Bicategory.Functor.Cat import Mathlib.CategoryTheory.Bicategory.LocallyDiscrete import Mathlib.CategoryTheory.Bicategory.Strict.Pseudofunctor import Mathlib.CategoryTheory.Sites.Sheaf import Mathlib.CategoryTheory.Sites.Over /-! # Prestacks: descent of morphisms Let `C` be a category and `F : LocallyDiscrete Cᵒᵖ ⥤ᵖ Cat`. Given `S : C`, and objects `M` and `N` in `F.obj (.mk (op S))`, we define a presheaf of types `F.presheafHom M N` on the category `Over S`: its sections on an object `T : Over S` corresponding to a morphism `p : X ⟶ S` are the type of morphisms `p^* M ⟶ p^* N`. We shall say that `F` satisfies the descent of morphisms for a Grothendieck topology `J` if these presheaves are all sheaves (typeclass `F.IsPrestack J`). ## Terminological note In this file, we use the language of pseudofunctors to formalize prestacks. Similar notions could also be phrased in terms of fibered categories. In the mathematical literature, various uses of the words "prestacks" and "stacks" exists. Our definitions are consistent with Giraud's definition II 1.2.1 in *Cohomologie non abélienne*: a prestack is defined by the descent of morphisms condition with respect to a Grothendieck topology, and a stack by the effectiveness of the descent. However, contrary to Laumon and Moret-Bailly in *Champs algébriques* 3.1, we do not require that target categories are groupoids. ## TODO * Relate this notion to the property that for any covering family `f i : X i ⟶ S` for `J`, the functor `F.obj S` to the category of objects in `F.obj (X i)` for all `i` equipped with a descent datum is fully faithful. * Define a typeclass `IsStack` (extending `IsPrestack`?) by saying that the functors mentioned above are essentially surjective. ## References * [Jean Giraud, *Cohomologie non abélienne*][giraud1971] * [Gérard Laumon and Laurent Moret-Bailly, *Champs algébriques*][laumon-morel-bailly-2000] -/ universe v' v u' u namespace CategoryTheory open Opposite Bicategory namespace Pseudofunctor variable {C : Type u} [Category.{v} C] {F : LocallyDiscrete Cᵒᵖ ⥤ᵖ Cat.{v', u'}} namespace LocallyDiscreteOpToCat /-- Given a pseudofunctor `F` from `LocallyDiscrete Cᵒᵖ` to `Cat`, objects `M₁` and `M₂` of `F` over `X₁` and `X₂`, morphisms `f₁ : Y ⟶ X₁` and `f₂ : Y ⟶ X₂`, this is a version of the pullback map `(f₁^* M₁ ⟶ f₂^* M₂) → (g^* (f₁^* M₁) ⟶ g^* (f₂^* M₂))` by a morphism `g : Y' ⟶ Y`, where we actually replace `g^* (f₁^* M₁)` by `gf₁^* M₁` where `gf₁ : Y' ⟶ X₁` is a morphism such that `g ≫ f₁ = gf₁` (and similarly for `M₂`). -/ def pullHom ⦃X₁ X₂ : C⦄ ⦃M₁ : F.obj (.mk (op X₁))⦄ ⦃M₂ : F.obj (.mk (op X₂))⦄ ⦃Y : C⦄ ⦃f₁ : Y ⟶ X₁⦄ ⦃f₂ : Y ⟶ X₂⦄ (φ : (F.map f₁.op.toLoc).obj M₁ ⟶ (F.map f₂.op.toLoc).obj M₂) ⦃Y' : C⦄ (g : Y' ⟶ Y) (gf₁ : Y' ⟶ X₁) (gf₂ : Y' ⟶ X₂) (hgf₁ : g ≫ f₁ = gf₁ := by cat_disch) (hgf₂ : g ≫ f₂ = gf₂ := by cat_disch) : (F.map gf₁.op.toLoc).obj M₁ ⟶ (F.map gf₂.op.toLoc).obj M₂ := (F.mapComp' f₁.op.toLoc g.op.toLoc gf₁.op.toLoc (by aesop)).hom.app _ ≫ (F.map g.op.toLoc).map φ ≫ (F.mapComp' f₂.op.toLoc g.op.toLoc gf₂.op.toLoc (by aesop)).inv.app _ @[reassoc] lemma map_eq_pullHom ⦃X₁ X₂ : C⦄ ⦃M₁ : F.obj (.mk (op X₁))⦄ ⦃M₂ : F.obj (.mk (op X₂))⦄ ⦃Y : C⦄ ⦃f₁ : Y ⟶ X₁⦄ ⦃f₂ : Y ⟶ X₂⦄ (φ : (F.map f₁.op.toLoc).obj M₁ ⟶ (F.map f₂.op.toLoc).obj M₂) ⦃Y' : C⦄ (g : Y' ⟶ Y) (gf₁ : Y' ⟶ X₁) (gf₂ : Y' ⟶ X₂) (hgf₁ : g ≫ f₁ = gf₁) (hgf₂ : g ≫ f₂ = gf₂) : (F.map g.op.toLoc).map φ = (F.mapComp' f₁.op.toLoc g.op.toLoc gf₁.op.toLoc (by aesop)).inv.app _ ≫ pullHom φ g gf₁ gf₂ hgf₁ hgf₂ ≫ (F.mapComp' f₂.op.toLoc g.op.toLoc gf₂.op.toLoc (by aesop)).hom.app _ := by simp [pullHom] @[simp] lemma pullHom_id ⦃X₁ X₂ : C⦄ ⦃M₁ : F.obj (.mk (op X₁))⦄ ⦃M₂ : F.obj (.mk (op X₂))⦄ ⦃Y : C⦄ ⦃f₁ : Y ⟶ X₁⦄ ⦃f₂ : Y ⟶ X₂⦄ (φ : (F.map f₁.op.toLoc).obj M₁ ⟶ (F.map f₂.op.toLoc).obj M₂) : pullHom φ (𝟙 _) f₁ f₂ = φ := by simp [pullHom, mapComp'_comp_id_hom_app, mapComp'_comp_id_inv_app] @[simp] lemma pullHom_pullHom ⦃X₁ X₂ : C⦄ ⦃M₁ : F.obj (.mk (op X₁))⦄ ⦃M₂ : F.obj (.mk (op X₂))⦄ ⦃Y : C⦄ ⦃f₁ : Y ⟶ X₁⦄ ⦃f₂ : Y ⟶ X₂⦄ (φ : (F.map f₁.op.toLoc).obj M₁ ⟶ (F.map f₂.op.toLoc).obj M₂) ⦃Y' : C⦄ (g : Y' ⟶ Y) (gf₁ : Y' ⟶ X₁) (gf₂ : Y' ⟶ X₂) ⦃Y'' : C⦄ (g' : Y'' ⟶ Y') (g'f₁ : Y'' ⟶ X₁) (g'f₂ : Y'' ⟶ X₂) (hgf₁ : g ≫ f₁ = gf₁ := by cat_disch) (hgf₂ : g ≫ f₂ = gf₂ := by cat_disch) (hg'f₁ : g' ≫ gf₁ = g'f₁ := by cat_disch) (hg'f₂ : g' ≫ gf₂ = g'f₂ := by cat_disch) : pullHom (pullHom φ g gf₁ gf₂ hgf₁ hgf₂) g' g'f₁ g'f₂ hg'f₁ hg'f₂ = pullHom φ (g' ≫ g) g'f₁ g'f₂ := by dsimp [pullHom] rw [Functor.map_comp_assoc, Functor.map_comp_assoc, F.mapComp'_inv_whiskerRight_mapComp'₀₂₃_inv_app _ _ _ _ _ _ _ rfl (by aesop), F.mapComp'₀₂₃_hom_comp_mapComp'_hom_whiskerRight_app_assoc _ _ _ _ _ _ _ rfl (by aesop), mapComp'_inv_naturality_assoc, Iso.hom_inv_id_app_assoc] end LocallyDiscreteOpToCat open LocallyDiscreteOpToCat section variable (F) {S : C} (M N : F.obj (.mk (op S))) /-- If `F` is a pseudofunctor from `Cᵒᵖ` to `Cat`, and `M` and `N` are objects in `F.obj (.mk (op S))`, this is the presheaf of morphisms from `M` to `N`: it sends an object `T : Over S` corresponding to a morphism `p : X ⟶ S` to the type of morphisms $$p^* M ⟶ p^* N$$. -/ @[simps] def presheafHom : (Over S)ᵒᵖ ⥤ Type v' where obj T := (F.map (.toLoc T.unop.hom.op)).obj M ⟶ (F.map (.toLoc T.unop.hom.op)).obj N map {T₁ T₂} p f := pullHom f p.unop.left T₂.unop.hom T₂.unop.hom /-- Compatiblity isomorphism of `Pseudofunctor.presheafHom` with "restrictions". -/ def overMapCompPresheafHomIso {S' : C} (q : S' ⟶ S) : (Over.map q).op ⋙ F.presheafHom M N ≅ F.presheafHom ((F.map (.toLoc q.op)).obj M) ((F.map (.toLoc q.op)).obj N) := NatIso.ofComponents (fun T ↦ Equiv.toIso (by letI e := F.mapComp' (.toLoc q.op) (.toLoc T.unop.hom.op) (.toLoc ((Over.map q).obj T.unop).hom.op) exact (Iso.homFromEquiv (e.app M)).trans (Iso.homToEquiv (e.app N)))) (by rintro ⟨T₁⟩ ⟨T₂⟩ ⟨f⟩ ext g dsimp [pullHom] simp only [Category.assoc, Functor.map_comp] rw [F.mapComp'₀₁₃_inv_comp_mapComp'₀₂₃_hom_app_assoc _ _ _ _ _ _ rfl _ rfl, F.mapComp'₀₂₃_inv_comp_mapComp'₀₁₃_hom_app _ _ _ _ _ _ _ _ (by simp only [← Quiver.Hom.comp_toLoc, ← op_comp, Over.w_assoc])]) end variable (F) /-- The property that a pseudofunctor `F : LocallyDiscrete Cᵒᵖ ⥤ᵖ Cat` satisfies the descent property for morphisms, i.e. is a prestack. (See the terminological note in the introduction of the file `Sites.Descent.IsPrestack`.) -/ @[stacks 026F "(2)"] class IsPrestack (J : GrothendieckTopology C) : Prop where isSheaf {S : C} (M N : F.obj (.mk (op S))) : Presheaf.IsSheaf (J.over S) (F.presheafHom M N) /-- If `F` is a prestack from `Cᵒᵖ` to `Cat` relatively to a Grothendieck topology `J`, and `M` and `N` are two objects in `F.obj (.mk (op S))`, this is the sheaf of morphisms from `M` to `N`: it sends an object `T : Over S` corresponding to a morphism `p : X ⟶ S` to the type of morphisms $$p^* M ⟶ p^* N$$. -/ @[simps] def sheafHom (J : GrothendieckTopology C) [F.IsPrestack J] {S : C} (M N : F.obj (.mk (op S))) : Sheaf (J.over S) (Type v') where val := F.presheafHom M N cond := IsPrestack.isSheaf _ _ end Pseudofunctor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Hypercover/IsSheaf.lean
import Mathlib.CategoryTheory.Sites.Hypercover.One /-! # Characterization of sheaves using 1-hypercovers In this file, given a Grothendieck topology `J` on a category `C`, we define a type `J.OneHypercoverFamily` of families of 1-hypercovers. When `H : J.OneHypercoverFamily`, we define a predicate `H.IsGenerating` which means that any covering sieve contains the sieve generated by the underlying covering of one of the 1-hypercovers in the family. If this holds, we show in `OneHypercoverFamily.isSheaf_iff` that a presheaf `P : Cᵒᵖ ⥤ A` is a sheaf iff for any 1-hypercover `E` in the family, the multifork `E.multifork P` is limit. There is a universe parameter `w` attached to `OneHypercoverFamily` and `OneHypercover`. This universe controls the "size" of the 1-hypercovers: the index types involved in the 1-hypercovers have to be in `Type w`. Then, we introduce a type class `GrothendieckTopology.IsGeneratedByOneHypercovers.{w} J` as an abbreviation for `OneHypercoverFamily.IsGenerating.{w} (J := J) ⊤`. We show that if `C : Type u` and `Category.{v} C`, then `GrothendieckTopology.IsGeneratedByOneHypercovers.{max u v} J` holds. ## TODO * Show that functors which preserve 1-hypercovers are continuous. * Refactor `DenseSubsite` using `1`-hypercovers. -/ universe w v v' u u' namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) {A : Type u'} [Category.{v'} A] namespace GrothendieckTopology /-- A family of 1-hypercovers consists of the data of a predicate on `OneHypercover.{w} J X` for all `X`. -/ abbrev OneHypercoverFamily := ∀ ⦃X : C⦄, OneHypercover.{w} J X → Prop namespace OneHypercoverFamily variable {J} variable (H : OneHypercoverFamily.{w} J) /-- A family of 1-hypercovers generates the topology if any covering sieve contains the sieve generated by the underlying covering of one of these 1-hypercovers. See `OneHypercoverFamily.isSheaf_iff` for the characterization of sheaves. -/ class IsGenerating : Prop where le {X : C} (S : Sieve X) (hS : S ∈ J X) : ∃ (E : J.OneHypercover X) (_ : H E), E.sieve₀ ≤ S lemma exists_oneHypercover [H.IsGenerating] {X : C} (S : Sieve X) (hS : S ∈ J X) : ∃ (E : J.OneHypercover X) (_ : H E), E.sieve₀ ≤ S := IsGenerating.le _ hS variable (P : Cᵒᵖ ⥤ A) namespace IsSheafIff variable (hP : ∀ ⦃X : C⦄ (E : J.OneHypercover X) (_ : H E), Nonempty (IsLimit (E.multifork P))) include hP in lemma hom_ext [H.IsGenerating] {X : C} (S : Sieve X) (hS : S ∈ J X) {T : A} {x y : T ⟶ P.obj (Opposite.op X)} (h : ∀ ⦃Y : C⦄ (f : Y ⟶ X) (_ : S f), x ≫ P.map f.op = y ≫ P.map f.op) : x = y := by obtain ⟨E, hE, le⟩ := H.exists_oneHypercover S hS exact Multifork.IsLimit.hom_ext (hP E hE).some (fun j => h _ (le _ (Sieve.ofArrows_mk _ _ _))) variable {P H} variable {X : C} {S : Sieve X} {E : J.OneHypercover X} (hE : H E) (le : E.sieve₀ ≤ S) section variable (F : Multifork (Cover.index ⟨S, J.superset_covering le E.mem₀⟩ P)) /-- Auxiliary definition for `isLimit`. -/ noncomputable def lift : F.pt ⟶ P.obj (Opposite.op X) := Multifork.IsLimit.lift (hP E hE).some (fun i => F.ι ⟨_, E.f i, le _ (Sieve.ofArrows_mk _ _ _)⟩) (fun ⟨⟨i₁, i₂⟩, j⟩ => F.condition { fst := { hf := le _ (Sieve.ofArrows_mk _ _ i₁), .. } snd := { hf := le _ (Sieve.ofArrows_mk _ _ i₂), .. } r := { w := E.w j, ..} }) @[reassoc] lemma fac' (i : E.I₀) : lift hP hE le F ≫ P.map (E.f i).op = F.ι ⟨_, E.f i, le _ (Sieve.ofArrows_mk _ _ _)⟩ := Multifork.IsLimit.fac (hP E hE).some _ _ i lemma fac [H.IsGenerating] {Y : C} (f : Y ⟶ X) (hf : S f) : lift hP hE le F ≫ P.map f.op = F.ι ⟨Y, f, hf⟩ := by apply hom_ext H P hP _ (J.pullback_stable f E.mem₀) intro Z g rintro ⟨T, a, b, ⟨i⟩, fac⟩ rw [assoc, ← P.map_comp, ← op_comp, ← fac, op_comp, P.map_comp, fac'_assoc] exact F.condition { fst := { hf := le _ (Sieve.ofArrows_mk _ _ _), .. } snd := { hf := hf, .. } r := { w := fac, ..} } end /-- Auxiliary definition for `OneHypercoverFamily.isSheaf_iff`. -/ noncomputable def isLimit [H.IsGenerating] : IsLimit (Cover.multifork ⟨S, J.superset_covering le E.mem₀⟩ P) := Multifork.IsLimit.mk _ (fun F => lift hP hE le F) (fun F => by rintro ⟨Y, f, hf⟩ apply fac) (fun F m hm => by apply hom_ext H P hP S (J.superset_covering le E.mem₀) intro Y f hf rw [fac _ _ _ _ _ hf] exact hm ⟨_, _, hf⟩) end IsSheafIff lemma isSheaf_iff [H.IsGenerating] : Presheaf.IsSheaf J P ↔ ∀ ⦃X : C⦄ (E : J.OneHypercover X) (_ : H E), Nonempty (IsLimit (E.multifork P)) := by constructor · intro hP X E _ exact ⟨E.isLimitMultifork ⟨_, hP⟩⟩ · intro hP rw [Presheaf.isSheaf_iff_multifork] rintro X ⟨S, hS⟩ obtain ⟨E, hE, le⟩ := H.exists_oneHypercover S hS exact ⟨IsSheafIff.isLimit hP hE le⟩ end OneHypercoverFamily /-- Condition that a topology is generated by 1-hypercovers of size `w`. -/ abbrev IsGeneratedByOneHypercovers : Prop := OneHypercoverFamily.IsGenerating.{w} (J := J) ⊤ instance : IsGeneratedByOneHypercovers.{max u v} J where le S hS := ⟨Cover.oneHypercover ⟨S, hS⟩, by simp, by simp⟩ end GrothendieckTopology namespace Presheaf lemma isSheaf_iff_of_isGeneratedByOneHypercovers [GrothendieckTopology.IsGeneratedByOneHypercovers.{w} J] (P : Cᵒᵖ ⥤ A) : IsSheaf J P ↔ ∀ ⦃X : C⦄ (E : GrothendieckTopology.OneHypercover.{w} J X), Nonempty (IsLimit (E.multifork P)) := by simpa using GrothendieckTopology.OneHypercoverFamily.isSheaf_iff.{w} ⊤ P end Presheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Hypercover/ZeroFamily.lean
import Mathlib.CategoryTheory.Sites.Hypercover.Zero /-! # Defining precoverages via pre-`0`-hypercovers A precoverage is a condition on all presieves. In some applications, it is practical to instead define a condition on all pre-`0`-hypercovers. Such a condition for every object is a pre-`0`-hypercover family if these conditions are invariant under deduplication. -/ universe w' w v u namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] variable (C) in /-- A pre-`0`-hypercover family on `C` is a property on the category of pre-`0`-hypercovers for every `X : C` that is invariant under deduplication. The data of a pre-`0`-hypercover family is the same as the data of a precoverage (see: `Precoverage.equivPreZeroHypercoverFamily`). -/ @[ext] structure PreZeroHypercoverFamily where /-- The condition on pre-`0`-hypercovers for every object. -/ property ⦃X : C⦄ : ObjectProperty (PreZeroHypercover.{max u v} X) iff_shrink {X : C} {E : PreZeroHypercover.{max u v} X} : property E ↔ property E.shrink instance : CoeFun (PreZeroHypercoverFamily C) fun _ ↦ ⦃X : C⦄ → (E : PreZeroHypercover.{max u v} X) → Prop where coe P := P.property /-- The induced condition on presieves in `C`, given by a pre-`0`-hypercover family. -/ inductive PreZeroHypercoverFamily.presieve (P : PreZeroHypercoverFamily C) {X : C} : Presieve X → Prop where | mk (E : PreZeroHypercover.{max u v} X) : P E → presieve P E.presieve₀ /-- The associated precoverage to a pre-`0`-hypercover family. -/ def PreZeroHypercoverFamily.precoverage (P : PreZeroHypercoverFamily C) : Precoverage C where coverings _ R := P.presieve R lemma PreZeroHypercoverFamily.mem_precoverage_iff {P : PreZeroHypercoverFamily C} {X : C} {R : Presieve X} : R ∈ P.precoverage X ↔ ∃ (E : PreZeroHypercover.{max u v} X), P E ∧ R = E.presieve₀ := ⟨fun ⟨E, hE⟩ ↦ ⟨E, hE, rfl⟩, fun ⟨_, hE, h⟩ ↦ h ▸ ⟨_, hE⟩⟩ @[simp] lemma PreZeroHypercover.presieve₀_mem_precoverage_iff {P : PreZeroHypercoverFamily C} {X : C} {E : PreZeroHypercover.{max u v} X} : E.presieve₀ ∈ P.precoverage X ↔ P E := by refine ⟨fun h ↦ ?_, fun h ↦ .mk _ h⟩ rw [PreZeroHypercoverFamily.mem_precoverage_iff] at h obtain ⟨F, h, heq⟩ := h rw [P.iff_shrink] at h ⊢ rwa [PreZeroHypercover.shrink_eq_shrink_of_presieve₀_eq_presieve₀ heq] /-- The associated pre-`0`-hypercover family to a precoverage. -/ @[simps] def Precoverage.preZeroHypercoverFamily (K : Precoverage C) : PreZeroHypercoverFamily C where property X E := E.presieve₀ ∈ K X iff_shrink {X} E := by simp variable (C) in /-- Giving a precoverage on a category is the same as giving a predicate on every pre-`0`-hypercover that is stable under deduplication. -/ def Precoverage.equivPreZeroHypercoverFamily : Precoverage C ≃ PreZeroHypercoverFamily C where toFun K := K.preZeroHypercoverFamily invFun P := P.precoverage left_inv K := by ext X R obtain ⟨E, rfl⟩ := R.exists_eq_preZeroHypercover simp right_inv P := by cat_disch lemma Precoverage.HasIsos.of_preZeroHypercoverFamily {P : PreZeroHypercoverFamily C} (h : ∀ ⦃X Y : C⦄ (f : X ⟶ Y) [IsIso f], P (.singleton f)) : P.precoverage.HasIsos where mem_coverings_of_isIso {S T} f hf := by rw [← PreZeroHypercover.presieve₀_singleton.{_, _, max u v}] refine .mk _ (h _) lemma Precoverage.IsStableUnderBaseChange.of_preZeroHypercoverFamily_of_isClosedUnderIsomorphisms {P : PreZeroHypercoverFamily C} (h₁ : ∀ {X : C}, (P (X := X)).IsClosedUnderIsomorphisms) (h₂ : ∀ {X Y : C} (f : X ⟶ Y) (E : PreZeroHypercover.{max u v} Y) [∀ (i : E.I₀), HasPullback f (E.f i)], P E → P (E.pullback₁ f)) : Precoverage.IsStableUnderBaseChange P.precoverage where mem_coverings_of_isPullback {ι} S X f hf Y g Z p₁ p₂ h := by let E : PreZeroHypercover S := ⟨ι, X, f⟩ have (i : E.I₀) : HasPullback g (E.f i) := (h i).hasPullback let F : PreZeroHypercover Y := ⟨_, _, p₁⟩ let e : F ≅ E.pullback₁ g := PreZeroHypercover.isoMk (Equiv.refl _) (fun i ↦ (h i).isoPullback) change F.presieve₀ ∈ _ rw [F.presieve₀_mem_precoverage_iff, (P (X := Y)).prop_iff_of_iso e] refine h₂ _ _ ?_ rwa [← E.presieve₀_mem_precoverage_iff] lemma Precoverage.IsStableUnderComposition.of_preZeroHypercoverFamily {P : PreZeroHypercoverFamily C} (h : ∀ {X : C} (E : PreZeroHypercover.{max u v} X) (F : ∀ i, PreZeroHypercover.{max u v} (E.X i)), P E → (∀ i, P (F i)) → P (E.bind F)) : Precoverage.IsStableUnderComposition P.precoverage where comp_mem_coverings {ι} S X f hf σ Y g hg := by let E : PreZeroHypercover S := ⟨_, _, f⟩ let F (i : ι) : PreZeroHypercover (E.X i) := ⟨_, _, g i⟩ refine (E.bind F).presieve₀_mem_precoverage_iff.mpr (h _ _ ?_ fun i ↦ ?_) · rwa [← E.presieve₀_mem_precoverage_iff] · rw [← (F i).presieve₀_mem_precoverage_iff] exact hg i end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Hypercover/One.lean
import Mathlib.CategoryTheory.Sites.Coverage import Mathlib.CategoryTheory.Sites.Sheaf import Mathlib.CategoryTheory.Sites.Hypercover.Zero /-! # 1-hypercovers Given a Grothendieck topology `J` on a category `C`, we define the type of `1`-hypercovers of an object `S : C`. They consists of a covering family of morphisms `X i ⟶ S` indexed by a type `I₀` and, for each tuple `(i₁, i₂)` of elements of `I₀`, a "covering `Y j` of the fibre product of `X i₁` and `X i₂` over `S`", a condition which is phrased here without assuming that the fibre product actually exist. The definition `OneHypercover.isLimitMultifork` shows that if `E` is a `1`-hypercover of `S`, and `F` is a sheaf, then `F.obj (op S)` identifies to the multiequalizer of suitable maps `F.obj (op (E.X i)) ⟶ F.obj (op (E.Y j))`. -/ universe w'' w' w v u namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] {A : Type*} [Category A] /-- The categorical data that is involved in a `1`-hypercover of an object `S`. This consists of a family of morphisms `f i : X i ⟶ S` for `i : I₀`, and for each tuple `(i₁, i₂)` of elements in `I₀`, a family of objects `Y j` indexed by a type `I₁ i₁ i₂`, which are equipped with a map to the fibre product of `X i₁` and `X i₂`, which is phrased here as the data of the two projections `p₁ : Y j ⟶ X i₁`, `p₂ : Y j ⟶ X i₂` and the relation `p₁ j ≫ f i₁ = p₂ j ≫ f i₂`. (See `GrothendieckTopology.OneHypercover` for the topological conditions.) -/ structure PreOneHypercover (S : C) extends PreZeroHypercover.{w} S where /-- the index type of the coverings of the fibre products -/ I₁ (i₁ i₂ : I₀) : Type w /-- the objects in the coverings of the fibre products -/ Y ⦃i₁ i₂ : I₀⦄ (j : I₁ i₁ i₂) : C /-- the first projection `Y j ⟶ X i₁` -/ p₁ ⦃i₁ i₂ : I₀⦄ (j : I₁ i₁ i₂) : Y j ⟶ X i₁ /-- the second projection `Y j ⟶ X i₂` -/ p₂ ⦃i₁ i₂ : I₀⦄ (j : I₁ i₁ i₂) : Y j ⟶ X i₂ w ⦃i₁ i₂ : I₀⦄ (j : I₁ i₁ i₂) : p₁ j ≫ f i₁ = p₂ j ≫ f i₂ namespace PreOneHypercover variable {S : C} (E : PreOneHypercover.{w} S) /-- Given an object `W` equipped with morphisms `p₁ : W ⟶ E.X i₁`, `p₂ : W ⟶ E.X i₂`, this is the sieve of `W` which consists of morphisms `g : Z ⟶ W` such that there exists `j` and `h : Z ⟶ E.Y j` such that `g ≫ p₁ = h ≫ E.p₁ j` and `g ≫ p₂ = h ≫ E.p₂ j`. See lemmas `sieve₁_eq_pullback_sieve₁'` and `sieve₁'_eq_sieve₁` for equational lemmas regarding this sieve. -/ @[simps] def sieve₁ {i₁ i₂ : E.I₀} {W : C} (p₁ : W ⟶ E.X i₁) (p₂ : W ⟶ E.X i₂) : Sieve W where arrows Z g := ∃ (j : E.I₁ i₁ i₂) (h : Z ⟶ E.Y j), g ≫ p₁ = h ≫ E.p₁ j ∧ g ≫ p₂ = h ≫ E.p₂ j downward_closed := by rintro Z Z' g ⟨j, h, fac₁, fac₂⟩ φ exact ⟨j, φ ≫ h, by simpa using φ ≫= fac₁, by simpa using φ ≫= fac₂⟩ section variable {i₁ i₂ : E.I₀} [HasPullback (E.f i₁) (E.f i₂)] /-- The obvious morphism `E.Y j ⟶ pullback (E.f i₁) (E.f i₂)` given by `E : PreOneHypercover S`. -/ noncomputable abbrev toPullback (j : E.I₁ i₁ i₂) [HasPullback (E.f i₁) (E.f i₂)] : E.Y j ⟶ pullback (E.f i₁) (E.f i₂) := pullback.lift (E.p₁ j) (E.p₂ j) (E.w j) variable (i₁ i₂) in /-- The sieve of `pullback (E.f i₁) (E.f i₂)` given by `E : PreOneHypercover S`. -/ noncomputable def sieve₁' : Sieve (pullback (E.f i₁) (E.f i₂)) := Sieve.ofArrows _ (fun (j : E.I₁ i₁ i₂) => E.toPullback j) lemma sieve₁_eq_pullback_sieve₁' {W : C} (p₁ : W ⟶ E.X i₁) (p₂ : W ⟶ E.X i₂) (w : p₁ ≫ E.f i₁ = p₂ ≫ E.f i₂) : E.sieve₁ p₁ p₂ = (E.sieve₁' i₁ i₂).pullback (pullback.lift _ _ w) := by ext Z g constructor · rintro ⟨j, h, fac₁, fac₂⟩ exact ⟨_, h, _, ⟨j⟩, by cat_disch⟩ · rintro ⟨_, h, w, ⟨j⟩, fac⟩ exact ⟨j, h, by simpa using fac.symm =≫ pullback.fst _ _, by simpa using fac.symm =≫ pullback.snd _ _⟩ variable (i₁ i₂) in lemma sieve₁'_eq_sieve₁ : E.sieve₁' i₁ i₂ = E.sieve₁ (pullback.fst _ _) (pullback.snd _ _) := by rw [← Sieve.pullback_id (S := E.sieve₁' i₁ i₂), sieve₁_eq_pullback_sieve₁' _ _ _ pullback.condition] congr cat_disch end /-- The sigma type of all `E.I₁ i₁ i₂` for `⟨i₁, i₂⟩ : E.I₀ × E.I₀`. -/ abbrev I₁' : Type w := Sigma (fun (i : E.I₀ × E.I₀) => E.I₁ i.1 i.2) /-- The shape of the multiforks attached to `E : PreOneHypercover S`. -/ @[simps] def multicospanShape : MulticospanShape where L := E.I₀ R := E.I₁' fst j := j.1.1 snd j := j.1.2 /-- The diagram of the multifork attached to a presheaf `F : Cᵒᵖ ⥤ A`, `S : C` and `E : PreOneHypercover S`. -/ @[simps] def multicospanIndex (F : Cᵒᵖ ⥤ A) : MulticospanIndex E.multicospanShape A where left i := F.obj (Opposite.op (E.X i)) right j := F.obj (Opposite.op (E.Y j.2)) fst j := F.map ((E.p₁ j.2).op) snd j := F.map ((E.p₂ j.2).op) /-- The multifork attached to a presheaf `F : Cᵒᵖ ⥤ A`, `S : C` and `E : PreOneHypercover S`. -/ def multifork (F : Cᵒᵖ ⥤ A) : Multifork (E.multicospanIndex F) := Multifork.ofι _ (F.obj (Opposite.op S)) (fun i₀ => F.map (E.f i₀).op) (by rintro ⟨⟨i₁, i₂⟩, (j : E.I₁ i₁ i₂)⟩ dsimp simp only [← F.map_comp, ← op_comp, E.w]) /-- The trivial pre-`1`-hypercover of `S` with a single component `S`. -/ @[simps toPreZeroHypercover I₁ Y p₁ p₂] def trivial (S : C) : PreOneHypercover.{w} S where __ := PreZeroHypercover.singleton (𝟙 S) I₁ _ _ := PUnit Y _ _ _ := S p₁ _ _ _ := 𝟙 _ p₂ _ _ _ := 𝟙 _ w _ _ _ := by simp lemma sieve₀_trivial (S : C) : (trivial S).sieve₀ = ⊤ := by rw [PreZeroHypercover.sieve₀, Sieve.ofArrows, ← PreZeroHypercover.presieve₀] simp @[simp] lemma sieve₁_trivial {S : C} {W : C} {p : W ⟶ S} : (trivial S).sieve₁ (i₁ := ⟨⟩) (i₂ := ⟨⟩) p p = ⊤ := by ext; simp instance : Nonempty (PreOneHypercover.{w} S) := ⟨trivial S⟩ section /-- Intersection of two pre-`1`-hypercovers. -/ @[simps toPreZeroHypercover I₁ Y p₁ p₂] noncomputable def inter (E F : PreOneHypercover S) [∀ i j, HasPullback (E.f i) (F.f j)] [∀ (i j : E.I₀) (k : E.I₁ i j) (a b : F.I₀) (l : F.I₁ a b), HasPullback (E.p₁ k ≫ E.f i) (F.p₁ l ≫ F.f a)] : PreOneHypercover S where __ := E.toPreZeroHypercover.inter F.toPreZeroHypercover I₁ i j := E.I₁ i.1 j.1 × F.I₁ i.2 j.2 Y i j k := pullback (E.p₁ k.1 ≫ E.f _) (F.p₁ k.2 ≫ F.f _) p₁ i j k := pullback.map _ _ _ _ (E.p₁ _) (F.p₁ _) (𝟙 S) (by simp) (by simp) p₂ i j k := pullback.map _ _ _ _ (E.p₂ _) (F.p₂ _) (𝟙 S) (by simp [E.w]) (by simp [F.w]) w := by simp [E.w] variable {E} {F : PreOneHypercover S} lemma sieve₁_inter [HasPullbacks C] {i j : E.I₀ × F.I₀} {W : C} {p₁ : W ⟶ pullback (E.f i.1) (F.f i.2)} {p₂ : W ⟶ pullback (E.f j.1) (F.f j.2)} (w : p₁ ≫ pullback.fst _ _ ≫ E.f _ = p₂ ≫ pullback.fst _ _ ≫ E.f _) : (inter E F).sieve₁ p₁ p₂ = Sieve.bind (E.sieve₁ (p₁ ≫ pullback.fst _ _) (p₂ ≫ pullback.fst _ _)) (fun _ f _ ↦ (F.sieve₁ (p₁ ≫ pullback.snd _ _) (p₂ ≫ pullback.snd _ _)).pullback f) := by ext Y f let p : W ⟶ pullback ((inter E F).f i) ((inter E F).f j) := pullback.lift p₁ p₂ w refine ⟨fun ⟨k, a, h₁, h₂⟩ ↦ ?_, fun ⟨Z, a, b, ⟨k, e, h₁, h₂⟩, ⟨l, u, u₁, u₂⟩, hab⟩ ↦ ?_⟩ · refine ⟨pullback p ((E.inter F).toPullback k), pullback.lift f a ?_, pullback.fst _ _, ?_, ?_, ?_⟩ · apply pullback.hom_ext · apply pullback.hom_ext <;> simp [p, h₁, toPullback] · apply pullback.hom_ext <;> simp [p, h₂, toPullback] · refine ⟨k.1, pullback.snd _ _ ≫ pullback.fst _ _, ?_, ?_⟩ · have : p₁ ≫ pullback.fst (E.f i.1) (F.f i.2) = p ≫ pullback.fst _ _ ≫ pullback.fst _ _ := by simp [p] simp [this, pullback.condition_assoc, toPullback] · have : p₂ ≫ pullback.fst (E.f j.1) (F.f j.2) = p ≫ pullback.snd _ _ ≫ pullback.fst _ _ := by simp [p] simp [this, pullback.condition_assoc, toPullback] · exact ⟨k.2, a ≫ pullback.snd _ _, by simp [reassoc_of% h₁], by simp [reassoc_of% h₂]⟩ · simp · subst hab refine ⟨(k, l), pullback.lift (a ≫ e) u ?_, ?_, ?_⟩ · simp only [Category.assoc] at u₁ simp [← reassoc_of% h₁, w, ← reassoc_of% u₁, ← pullback.condition] · apply pullback.hom_ext · simp [h₁] · simpa using u₁ · apply pullback.hom_ext · simp [h₂] · simpa using u₂ end section Category /-- A morphism of pre-`1`-hypercovers of `S` is a family of refinement morphisms commuting with the structure morphisms of `E` and `F`. -/ @[ext] structure Hom (E F : PreOneHypercover S) extends E.toPreZeroHypercover.Hom F.toPreZeroHypercover where /-- The map between indexing types of the coverings of the fibre products over `S`. -/ s₁ {i j : E.I₀} (k : E.I₁ i j) : F.I₁ (s₀ i) (s₀ j) /-- The refinement morphisms between objects in the coverings of the fibre products over `S`. -/ h₁ {i j : E.I₀} (k : E.I₁ i j) : E.Y k ⟶ F.Y (s₁ k) w₁₁ {i j : E.I₀} (k : E.I₁ i j) : h₁ k ≫ F.p₁ (s₁ k) = E.p₁ k ≫ h₀ i := by cat_disch w₁₂ {i j : E.I₀} (k : E.I₁ i j) : h₁ k ≫ F.p₂ (s₁ k) = E.p₂ k ≫ h₀ j := by cat_disch attribute [reassoc] Hom.w₁₁ Hom.w₁₂ /-- The identity refinement of a pre-`1`-hypercover. -/ @[simps!] def Hom.id (E : PreOneHypercover S) : Hom E E where __ := PreZeroHypercover.Hom.id _ s₁ := _root_.id h₁ _ := 𝟙 _ variable {E : PreOneHypercover.{w} S} {F : PreOneHypercover.{w'} S} {G : PreOneHypercover S} /-- Composition of refinement morphisms of pre-`1`-hypercovers. -/ @[simps!] def Hom.comp (f : E.Hom F) (g : F.Hom G) : E.Hom G where __ := PreZeroHypercover.Hom.comp _ _ s₁ := g.s₁ ∘ f.s₁ h₁ i := f.h₁ i ≫ g.h₁ _ w₁₁ := by simp [w₁₁, w₁₁_assoc] w₁₂ := by simp [w₁₂, w₁₂_assoc] /-- The induced index map `E.I₁' → F.I₁'` from a refinement morphism `E ⟶ F`. -/ @[simp] def Hom.s₁' (f : E.Hom F) (k : E.I₁') : F.I₁' := ⟨⟨f.s₀ k.1.1, f.s₀ k.1.2⟩, f.s₁ k.2⟩ @[simps! id_s₀ id_s₁ id_h₀ id_h₁ comp_s₀ comp_s₁ comp_h₀ comp_h₁] instance : Category (PreOneHypercover S) where Hom := Hom id E := Hom.id E comp f g := f.comp g /-- The forgetful functor from pre-`1`-hypercovers to pre-`0`-hypercovers. -/ @[simps] def oneToZero : PreOneHypercover.{w} S ⥤ PreZeroHypercover.{w} S where obj f := f.1 map f := f.1 /-- A refinement morphism `E ⟶ F` induces a morphism on associated multiequalizers. -/ def Hom.mapMultiforkOfIsLimit (f : E.Hom F) (P : Cᵒᵖ ⥤ A) {c : Multifork (E.multicospanIndex P)} (hc : IsLimit c) (d : Multifork (F.multicospanIndex P)) : d.pt ⟶ c.pt := Multifork.IsLimit.lift hc (fun a ↦ d.ι (f.s₀ a) ≫ P.map (f.h₀ a).op) <| by intro (k : E.I₁') simp only [multicospanIndex_right, multicospanShape_fst, multicospanIndex_left, multicospanIndex_fst, assoc, multicospanShape_snd, multicospanIndex_snd] have heq := d.condition (f.s₁' k) simp only [Hom.s₁', multicospanIndex_right, multicospanShape_fst, multicospanIndex_left, multicospanIndex_fst, multicospanShape_snd, multicospanIndex_snd] at heq rw [← Functor.map_comp, ← op_comp, ← Hom.w₁₁, ← Functor.map_comp, ← op_comp, ← Hom.w₁₂] rw [op_comp, Functor.map_comp, reassoc_of% heq, op_comp, Functor.map_comp] @[reassoc (attr := simp)] lemma Hom.mapMultiforkOfIsLimit_ι {E F : PreOneHypercover.{w} S} (f : E.Hom F) (P : Cᵒᵖ ⥤ A) {c : Multifork (E.multicospanIndex P)} (hc : IsLimit c) (d : Multifork (F.multicospanIndex P)) (a : E.I₀) : f.mapMultiforkOfIsLimit P hc d ≫ c.ι a = d.ι (f.s₀ a) ≫ P.map (f.h₀ a).op := by simp [mapMultiforkOfIsLimit] end Category section variable (F : PreOneHypercover.{w'} S) {G : PreOneHypercover.{w''} S} [∀ (i : E.I₀) (j : F.I₀), HasPullback (E.f i) (F.f j)] [∀ (i j : E.I₀) (k : E.I₁ i j) (a b : F.I₀) (l : F.I₁ a b), HasPullback (E.p₁ k ≫ E.f i) (F.p₁ l ≫ F.f a)] /-- First projection from the intersection of two pre-`1`-hypercovers. -/ @[simps toHom s₁] noncomputable def interFst : (E.inter F).Hom E where __ := E.toPreZeroHypercover.interFst F.toPreZeroHypercover s₁ {i j} k := k.1 h₁ _ := pullback.fst _ _ /-- Second projection from the intersection of two pre-`1`-hypercovers. -/ @[simps toHom s₁] noncomputable def interSnd : (E.inter F).Hom F where __ := E.toPreZeroHypercover.interSnd F.toPreZeroHypercover s₁ {i j} k := k.2 h₁ _ := pullback.snd _ _ variable {E F} in /-- Universal property of the intersection of two pre-`1`-hypercovers. -/ noncomputable def interLift {G : PreOneHypercover.{w''} S} (f : G.Hom E) (g : G.Hom F) : G.Hom (E.inter F) where __ := PreZeroHypercover.interLift f.toHom g.toHom s₁ {i j} k := ⟨f.s₁ k, g.s₁ k⟩ h₁ k := pullback.lift (f.h₁ k) (g.h₁ k) <| by rw [f.w₁₁_assoc k, g.w₁₁_assoc k] simp w₀ := by simp w₁₁ k := by apply pullback.hom_ext · simpa using f.w₁₁ k · simpa using g.w₁₁ k w₁₂ k := by apply pullback.hom_ext · simpa using f.w₁₂ k · simpa using g.w₁₂ k end end PreOneHypercover namespace GrothendieckTopology variable (J : GrothendieckTopology C) /-- The type of `1`-hypercovers of an object `S : C` in a category equipped with a Grothendieck topology `J`. This can be constructed from a covering of `S` and a covering of the fibre products of the objects in this covering (see `OneHypercover.mk'`). -/ structure OneHypercover (S : C) extends PreOneHypercover.{w} S where mem₀ : toPreOneHypercover.sieve₀ ∈ J S mem₁ (i₁ i₂ : I₀) ⦃W : C⦄ (p₁ : W ⟶ X i₁) (p₂ : W ⟶ X i₂) (w : p₁ ≫ f i₁ = p₂ ≫ f i₂) : toPreOneHypercover.sieve₁ p₁ p₂ ∈ J W variable {J} lemma OneHypercover.mem_sieve₁' {S : C} (E : J.OneHypercover S) (i₁ i₂ : E.I₀) [HasPullback (E.f i₁) (E.f i₂)] : E.sieve₁' i₁ i₂ ∈ J _ := by rw [E.sieve₁'_eq_sieve₁] exact mem₁ _ _ _ _ _ pullback.condition namespace OneHypercover /-- In order to check that a certain data is a `1`-hypercover of `S`, it suffices to check that the data provides a covering of `S` and of the fibre products. -/ @[simps toPreOneHypercover] def mk' {S : C} (E : PreOneHypercover S) [E.HasPullbacks] (mem₀ : E.sieve₀ ∈ J S) (mem₁' : ∀ (i₁ i₂ : E.I₀), E.sieve₁' i₁ i₂ ∈ J _) : J.OneHypercover S where toPreOneHypercover := E mem₀ := mem₀ mem₁ i₁ i₂ W p₁ p₂ w := by rw [E.sieve₁_eq_pullback_sieve₁' _ _ w] exact J.pullback_stable' _ (mem₁' i₁ i₂) section variable {S : C} (E : J.OneHypercover S) (F : Sheaf J A) section variable {E F} variable (c : Multifork (E.multicospanIndex F.val)) /-- Auxiliary definition of `isLimitMultifork`. -/ noncomputable def multiforkLift : c.pt ⟶ F.val.obj (Opposite.op S) := F.cond.amalgamateOfArrows _ E.mem₀ c.ι (fun W i₁ i₂ p₁ p₂ w => by apply F.cond.hom_ext ⟨_, E.mem₁ _ _ _ _ w⟩ rintro ⟨T, g, j, h, fac₁, fac₂⟩ dsimp simp only [assoc, ← Functor.map_comp, ← op_comp, fac₁, fac₂] simp only [op_comp, Functor.map_comp] simpa using c.condition ⟨⟨i₁, i₂⟩, j⟩ =≫ F.val.map h.op) @[reassoc] lemma multiforkLift_map (i₀ : E.I₀) : multiforkLift c ≫ F.val.map (E.f i₀).op = c.ι i₀ := by simp [multiforkLift] end /-- If `E : J.OneHypercover S` and `F : Sheaf J A`, then `F.obj (op S)` is a multiequalizer of suitable maps `F.obj (op (E.X i)) ⟶ F.obj (op (E.Y j))` induced by `E.p₁ j` and `E.p₂ j`. -/ noncomputable def isLimitMultifork : IsLimit (E.multifork F.1) := Multifork.IsLimit.mk _ (fun c => multiforkLift c) (fun c => multiforkLift_map c) (by intro c m hm apply F.cond.hom_ext_ofArrows _ E.mem₀ intro i₀ dsimp only rw [multiforkLift_map] exact hm i₀) end section variable {S : C} /-- Forget the `1`-components of a `OneHypercover`. -/ @[simps toPreZeroHypercover] def toZeroHypercover (E : OneHypercover.{w} J S) : J.toPrecoverage.ZeroHypercover S where __ := E.toPreZeroHypercover mem₀ := E.mem₀ variable (J) in /-- The trivial `1`-hypercover of `S` where a single component `S`. -/ @[simps toPreOneHypercover] def trivial (S : C) : OneHypercover.{w} J S where __ := PreOneHypercover.trivial S mem₀ := by simp only [PreOneHypercover.sieve₀_trivial, J.top_mem] mem₁ _ _ _ _ _ h := by simp only [PreOneHypercover.trivial_toPreZeroHypercover, PreZeroHypercover.singleton_X, PreZeroHypercover.singleton_f, Category.comp_id] at h subst h simp instance (S : C) : Nonempty (J.OneHypercover S) := ⟨trivial J S⟩ /-- Intersection of two `1`-hypercovers. -/ @[simps toPreOneHypercover] noncomputable def inter [HasPullbacks C] (E F : J.OneHypercover S) [∀ (i : E.I₀) (j : F.I₀), HasPullback (E.f i) (F.f j)] [∀ (i j : E.I₀) (k : E.I₁ i j) (a b : F.I₀) (l : F.I₁ a b), HasPullback (E.p₁ k ≫ E.f i) (F.p₁ l ≫ F.f a)] : J.OneHypercover S where __ := E.toPreOneHypercover.inter F.toPreOneHypercover mem₀ := (E.toZeroHypercover.inter F.toZeroHypercover).mem₀ mem₁ i₁ i₂ W p₁ p₂ h := by rw [PreOneHypercover.sieve₁_inter h] refine J.bind_covering (E.mem₁ _ _ _ _ (by simpa using h)) fun _ _ _ ↦ ?_ exact J.pullback_stable _ (F.mem₁ _ _ _ _ (by simpa [Category.assoc, ← pullback.condition])) end section Category variable {S : C} {E : OneHypercover.{w} J S} {F : OneHypercover.{w'} J S} /-- A morphism of `1`-hypercovers is a morphism of the underlying pre-`1`-hypercovers. -/ abbrev Hom (E : OneHypercover.{w} J S) (F : OneHypercover.{w'} J S) := E.toPreOneHypercover.Hom F.toPreOneHypercover @[simps! id_s₀ id_s₁ id_h₀ id_h₁ comp_s₀ comp_s₁ comp_h₀ comp_h₁] instance : Category (J.OneHypercover S) where Hom := Hom id E := PreOneHypercover.Hom.id E.toPreOneHypercover comp f g := f.comp g /-- An isomorphism of `1`-hypercovers is an isomorphism of pre-`1`-hypercovers. -/ @[simps] def isoMk {E F : J.OneHypercover S} (f : E.toPreOneHypercover ≅ F.toPreOneHypercover) : E ≅ F where __ := f end Category end OneHypercover namespace Cover variable {X : C} (S : J.Cover X) /-- The tautological 1-pre-hypercover induced by `S : J.Cover X`. Its index type `I₀` is given by `S.Arrow` (i.e. all the morphisms in the sieve `S`), while `I₁` is given by all possible pullback cones. -/ @[simps] def preOneHypercover : PreOneHypercover.{max u v} X where I₀ := S.Arrow X f := f.Y f f := f.f I₁ f₁ f₂ := f₁.Relation f₂ Y _ _ r := r.Z p₁ _ _ r := r.g₁ p₂ _ _ r := r.g₂ w _ _ r := r.w @[simp] lemma preOneHypercover_sieve₀ : S.preOneHypercover.sieve₀ = S.1 := by ext Y f constructor · rintro ⟨_, _, _, ⟨g⟩, rfl⟩ exact S.1.downward_closed g.hf _ · intro hf exact Sieve.ofArrows_mk _ _ ({ hf := hf, .. } : S.Arrow) lemma preOneHypercover_sieve₁ (f₁ f₂ : S.Arrow) {W : C} (p₁ : W ⟶ f₁.Y) (p₂ : W ⟶ f₂.Y) (w : p₁ ≫ f₁.f = p₂ ≫ f₂.f) : S.preOneHypercover.sieve₁ p₁ p₂ = ⊤ := by ext Y f simp only [Sieve.top_apply, iff_true] exact ⟨{ w := w, .. }, f, rfl, rfl⟩ /-- The tautological 1-hypercover induced by `S : J.Cover X`. Its index type `I₀` is given by `S.Arrow` (i.e. all the morphisms in the sieve `S`), while `I₁` is given by all possible pullback cones. -/ @[simps toPreOneHypercover] def oneHypercover : J.OneHypercover X where toPreOneHypercover := S.preOneHypercover mem₀ := by simp mem₁ f₁ f₂ _ p₁ p₂ w := by simp [S.preOneHypercover_sieve₁ f₁ f₂ p₁ p₂ w] end Cover end GrothendieckTopology end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Hypercover/Zero.lean
import Mathlib.CategoryTheory.Sites.Precoverage /-! # 0-hypercovers Given a coverage `J` on a category `C`, we define the type of `0`-hypercovers of an object `S : C`. They consists of a covering family of morphisms `X i ⟶ S` indexed by a type `I₀` such that the induced presieve is in `J`. We define this with respect to a coverage and not to a Grothendieck topology, because this yields more control over the components of the cover. -/ universe w'' w' w v u namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] /-- The categorical data that is involved in a `0`-hypercover of an object `S`. This consists of a family of morphisms `f i : X i ⟶ S` for `i : I₀`. -/ @[ext] structure PreZeroHypercover (S : C) where /-- the index type of the covering of `S` -/ I₀ : Type w /-- the objects in the covering of `S` -/ X (i : I₀) : C /-- the morphisms in the covering of `S` -/ f (i : I₀) : X i ⟶ S namespace PreZeroHypercover variable {S T : C} (E : PreZeroHypercover.{w} S) (F : PreZeroHypercover.{w'} S) /-- The assumption that the pullback of `X i₁` and `X i₂` over `S` exists for any `i₁` and `i₂`. -/ abbrev HasPullbacks := ∀ (i₁ i₂ : E.I₀), HasPullback (E.f i₁) (E.f i₂) /-- The presieve of `S` that is generated by the morphisms `f i : X i ⟶ S`. -/ abbrev presieve₀ : Presieve S := .ofArrows _ E.f @[simp] lemma presieve₀_f (i : E.I₀) : E.presieve₀ (E.f i) := ⟨i⟩ grind_pattern presieve₀_f => E.presieve₀ (E.f i) /-- The sieve of `S` that is generated by the morphisms `f i : X i ⟶ S`. -/ abbrev sieve₀ : Sieve S := .ofArrows _ E.f lemma sieve₀_f (i : E.I₀) : E.sieve₀ (E.f i) := ⟨_, 𝟙 _, E.f i, ⟨i⟩, by simp⟩ grind_pattern sieve₀_f => E.sieve₀ (E.f i) /-- The pre-`0`-hypercover defined by a single morphism. -/ @[simps] def singleton (f : S ⟶ T) : PreZeroHypercover.{w} T where I₀ := PUnit X _ := S f _ := f @[simp] lemma presieve₀_singleton (f : S ⟶ T) : (singleton f).presieve₀ = .singleton f := by simp [singleton, presieve₀, Presieve.ofArrows_pUnit] instance (f : S ⟶ T) : Unique (PreZeroHypercover.singleton f).I₀ := inferInstanceAs <| Unique PUnit /-- Pullback of a pre-`0`-hypercover along a morphism. The components are `pullback f (E.f i)`. -/ @[simps] noncomputable def pullback₁ (f : S ⟶ T) (E : PreZeroHypercover.{w} T) [∀ i, HasPullback f (E.f i)] : PreZeroHypercover.{w} S where I₀ := E.I₀ X i := pullback f (E.f i) f _ := pullback.fst _ _ /-- Pullback of a pre-`0`-hypercover along a morphism. The components are `pullback (E.f i) f`. -/ @[simps] noncomputable def pullback₂ (f : S ⟶ T) (E : PreZeroHypercover.{w} T) [∀ i, HasPullback (E.f i) f] : PreZeroHypercover.{w} S where I₀ := E.I₀ X i := pullback (E.f i) f f _ := pullback.snd _ _ lemma presieve₀_pullback₁ (f : S ⟶ T) (E : PreZeroHypercover.{w} T) [∀ i, HasPullback (E.f i) f] : presieve₀ (E.pullback₂ f) = E.presieve₀.pullbackArrows f := by refine le_antisymm ?_ ?_ · rintro - - ⟨i⟩ use _, _, i · rintro W g ⟨-, -, ⟨i⟩⟩ use i /-- Refining each component of a pre-`0`-hypercover yields a refined pre-`0`-hypercover of the base. -/ @[simps] def bind (E : PreZeroHypercover.{w} T) (F : ∀ i, PreZeroHypercover.{w'} (E.X i)) : PreZeroHypercover.{max w w'} T where I₀ := Σ (i : E.I₀), (F i).I₀ X ij := (F ij.1).X ij.2 f ij := (F ij.1).f ij.2 ≫ E.f ij.1 /-- Restrict the indexing type to `ι` by precomposing with a function `ι → E.I₀`. -/ @[simps] def restrictIndex (E : PreZeroHypercover.{w} T) {ι : Type w'} (f : ι → E.I₀) : PreZeroHypercover.{w'} T where I₀ := ι X := E.X ∘ f f i := E.f (f i) @[simp] lemma presieve₀_restrictIndex_equiv {ι : Type w'} (e : ι ≃ E.I₀) : (E.restrictIndex e).presieve₀ = E.presieve₀ := by refine le_antisymm (fun Y g ⟨i⟩ ↦ ⟨e i⟩) fun Y g ⟨i⟩ ↦ ?_ obtain ⟨i, rfl⟩ := e.surjective i exact ⟨i⟩ /-- Replace the indexing type of a pre-`0`-hypercover. -/ @[simps!] def reindex (E : PreZeroHypercover.{w} T) {ι : Type w'} (e : ι ≃ E.I₀) : PreZeroHypercover.{w'} T := E.restrictIndex e @[simp] lemma presieve₀_reindex {ι : Type w'} (e : ι ≃ E.I₀) : (E.reindex e).presieve₀ = E.presieve₀ := by simp [reindex] /-- Pairwise intersection of two pre-`0`-hypercovers. -/ @[simps!] noncomputable def inter (E : PreZeroHypercover.{w} T) (F : PreZeroHypercover.{w'} T) [∀ i j, HasPullback (E.f i) (F.f j)] : PreZeroHypercover.{max w w'} T := (E.bind (fun i ↦ F.pullback₁ (E.f i))).reindex (Equiv.sigmaEquivProd _ _).symm lemma inter_def [∀ i j, HasPullback (E.f i) (F.f j)] : E.inter F = (E.bind (fun i ↦ F.pullback₁ (E.f i))).reindex (Equiv.sigmaEquivProd _ _).symm := rfl /-- Disjoint union of two pre-`0`-hypercovers. -/ @[simps I₀, simps -isSimp X f] def sum {X : C} (E : PreZeroHypercover.{w} X) (F : PreZeroHypercover.{w'} X) : PreZeroHypercover.{max w w'} X where I₀ := E.I₀ ⊕ F.I₀ X := Sum.elim E.X F.X f | .inl i => E.f i | .inr i => F.f i @[simp] lemma sum_X_inl (i : E.I₀) : (E.sum F).X (.inl i) = E.X i := rfl @[simp] lemma sum_X_inr (i : F.I₀) : (E.sum F).X (.inr i) = F.X i := rfl @[simp] lemma sum_f_inl (i : E.I₀) : (E.sum F).f (.inl i) = E.f i := rfl @[simp] lemma sum_f_inr (i : F.I₀) : (E.sum F).f (.inr i) = F.f i := rfl @[simp] lemma presieve₀_sum : (E.sum F).presieve₀ = E.presieve₀ ⊔ F.presieve₀ := by rw [presieve₀, presieve₀, presieve₀] apply le_antisymm · intro Z g ⟨i⟩ cases i · exact Or.inl (.mk _) · exact Or.inr (.mk _) · rintro Z g (⟨⟨i⟩⟩|⟨⟨i⟩⟩) · exact ⟨Sum.inl i⟩ · exact ⟨Sum.inr i⟩ /-- Add a morphism to a pre-`0`-hypercover. -/ @[simps! I₀] def add (E : PreZeroHypercover.{w} S) {T : C} (f : T ⟶ S) : PreZeroHypercover.{w} S := (E.sum (.singleton f)).reindex (Equiv.optionEquivSumPUnit.{0} E.I₀) @[simp] lemma add_X_some {T : C} (f : T ⟶ S) (i : E.I₀) : (E.add f).X (some i) = E.X i := rfl @[simp] lemma add_X_none {T : C} (f : T ⟶ S) : (E.add f).X none = T := rfl @[simp] lemma add_f_some {T : C} (f : T ⟶ S) (i : E.I₀) : (E.add f).f (some i) = E.f i := rfl @[simp] lemma add_f_nome {T : C} (f : T ⟶ S) : (E.add f).f none = f := rfl @[simp] lemma presieve₀_add {T : C} (f : T ⟶ S) : (E.add f).presieve₀ = E.presieve₀ ⊔ .singleton f := by simp [add, presieve₀_reindex, presieve₀_sum] section Category variable {E : PreZeroHypercover.{w} S} {F : PreZeroHypercover.{w'} S} /-- A morphism of pre-`0`-hypercovers of `S` is a family of refinement morphisms commuting with the structure morphisms of `E` and `F`. -/ @[ext] structure Hom (E : PreZeroHypercover.{w} S) (F : PreZeroHypercover.{w'} S) where /-- The map between indexing types of the coverings of `S` -/ s₀ (i : E.I₀) : F.I₀ /-- The refinement morphisms between objects in the coverings of `S`. -/ h₀ (i : E.I₀) : E.X i ⟶ F.X (s₀ i) w₀ (i : E.I₀) : h₀ i ≫ F.f (s₀ i) = E.f i := by cat_disch attribute [reassoc (attr := simp)] Hom.w₀ /-- The identity refinement of a pre-`0`-hypercover. -/ @[simps] def Hom.id (E : PreZeroHypercover S) : Hom E E where s₀ := _root_.id h₀ _ := 𝟙 _ variable {G : PreZeroHypercover S} /-- Composition of refinement morphisms of pre-`0`-hypercovers. -/ @[simps] def Hom.comp (f : E.Hom F) (g : F.Hom G) : E.Hom G where s₀ := g.s₀ ∘ f.s₀ h₀ i := f.h₀ i ≫ g.h₀ _ @[simps! id_s₀ id_h₀ comp_s₀ comp_h₀] instance : Category (PreZeroHypercover S) where Hom := Hom id E := Hom.id E comp f g := f.comp g lemma Hom.ext' {E : PreZeroHypercover.{w} S} {F : PreZeroHypercover.{w'} S} {f g : E.Hom F} (hs : f.s₀ = g.s₀) (hh : ∀ i, f.h₀ i = g.h₀ i ≫ eqToHom (by rw [hs])) : f = g := by cases f cases g simp only at hs cat_disch lemma Hom.ext'_iff {E : PreZeroHypercover.{w} S} {F : PreZeroHypercover.{w'} S} {f g : E.Hom F} : f = g ↔ ∃ (hs : f.s₀ = g.s₀), ∀ i, f.h₀ i = g.h₀ i ≫ eqToHom (by rw [hs]) := ⟨fun h ↦ h ▸ by simp, fun ⟨hs, hh⟩ ↦ Hom.ext' hs hh⟩ /-- Constructor for isomorphisms of pre-`0`-hypercovers. -/ @[simps] def isoMk {S : C} {E F : PreZeroHypercover.{w} S} (s₀ : E.I₀ ≃ F.I₀) (h₀ : ∀ i, E.X i ≅ F.X (s₀ i)) (w₀ : ∀ i, (h₀ i).hom ≫ F.f _ = E.f _ := by cat_disch) : E ≅ F where hom.s₀ := s₀ hom.h₀ i := (h₀ i).hom inv.s₀ := s₀.symm inv.h₀ i := eqToHom (by simp) ≫ (h₀ _).inv inv.w₀ i := by obtain ⟨i, rfl⟩ := s₀.surjective i simp only [← cancel_epi (h₀ i).hom, w₀, Category.assoc, Equiv.symm_apply_apply, eqToHom_iso_hom_naturality_assoc, Iso.hom_inv_id_assoc] rw [← CategoryTheory.eqToHom_naturality _ (by simp)] simp hom_inv_id := Hom.ext' (by ext; simp) (fun i ↦ by simp) inv_hom_id := Hom.ext' (by ext; simp) (fun i ↦ by simp) @[simp] lemma hom_inv_s₀_apply {E F : PreZeroHypercover.{w} S} (e : E ≅ F) (i : E.I₀) : e.inv.s₀ (e.hom.s₀ i) = i := congr($(e.hom_inv_id).s₀ i) @[simp] lemma inv_hom_s₀_apply {E F : PreZeroHypercover.{w} S} (e : E ≅ F) (i : F.I₀) : e.hom.s₀ (e.inv.s₀ i) = i := congr($(e.inv_hom_id).s₀ i) @[reassoc (attr := simp)] lemma hom_inv_h₀ {E F : PreZeroHypercover.{w} S} (e : E ≅ F) (i : E.I₀) : e.hom.h₀ i ≫ e.inv.h₀ (e.hom.s₀ i) = eqToHom (by simp) := by obtain ⟨hs, hh⟩ := Hom.ext'_iff.mp e.hom_inv_id simpa using hh i @[reassoc (attr := simp)] lemma inv_hom_h₀ {E F : PreZeroHypercover.{w} S} (e : E ≅ F) (i : F.I₀) : e.inv.h₀ i ≫ e.hom.h₀ (e.inv.s₀ i) = eqToHom (by simp) := by obtain ⟨hs, hh⟩ := Hom.ext'_iff.mp e.inv_hom_id simpa using hh i instance {E F : PreZeroHypercover.{w} S} (e : E ≅ F) (i : E.I₀) : IsIso (e.hom.h₀ i) := by use e.inv.h₀ (e.hom.s₀ i) ≫ eqToHom (by simp) rw [hom_inv_h₀_assoc, eqToHom_trans, eqToHom_refl, Category.assoc, ← eqToHom_naturality _ (by simp), inv_hom_h₀_assoc] simp instance {E F : PreZeroHypercover.{w} S} (e : E ≅ F) (i : F.I₀) : IsIso (e.inv.h₀ i) := .of_isIso_fac_right (inv_hom_h₀ e i) end Category section Functoriality variable {D : Type*} [Category D] {F : C ⥤ D} /-- The image of a pre-`0`-hypercover under a functor. -/ @[simps] def map (F : C ⥤ D) (E : PreZeroHypercover.{w} S) : PreZeroHypercover.{w} (F.obj S) where I₀ := E.I₀ X i := F.obj (E.X i) f i := F.map (E.f i) lemma presieve₀_map : (E.map F).presieve₀ = E.presieve₀.map F := (Presieve.map_ofArrows _).symm end Functoriality /-- Pullback symmetry isomorphism. -/ @[simps] noncomputable def pullbackIso {S T : C} (f : S ⟶ T) (E : PreZeroHypercover.{w} T) [∀ (i : E.I₀), HasPullback f (E.f i)] [∀ (i : E.I₀), HasPullback (E.f i) f] : E.pullback₁ f ≅ E.pullback₂ f where hom.s₀ := id hom.h₀ i := (pullbackSymmetry _ _).hom inv.s₀ := id inv.h₀ i := (pullbackSymmetry _ _).inv hom_inv_id := by apply Hom.ext (by rfl) simp only [heq_eq_eq] ext i simp inv_hom_id := by apply Hom.ext (by rfl) simp only [heq_eq_eq] ext i simp section variable (F : PreZeroHypercover.{w'} S) {G : PreZeroHypercover.{w''} S} /-- The left inclusion into the disjoint union. -/ @[simps] def sumInl : E.Hom (E.sum F) where s₀ := Sum.inl h₀ _ := 𝟙 _ /-- The right inclusion into the disjoint union. -/ @[simps] def sumInr : F.Hom (E.sum F) where s₀ := Sum.inr h₀ _ := 𝟙 _ variable {E F} in /-- To give a refinement of the disjoint union, it suffices to give refinements of both components. -/ @[simps] def sumLift (f : E.Hom G) (g : F.Hom G) : (E.sum F).Hom G where s₀ := Sum.elim f.s₀ g.s₀ h₀ | .inl i => f.h₀ i | .inr i => g.h₀ i variable [∀ (i : E.I₀) (j : F.I₀), HasPullback (E.f i) (F.f j)] /-- First projection from the intersection of two pre-`0`-hypercovers. -/ @[simps] noncomputable def interFst : Hom (inter E F) E where s₀ i := i.1 h₀ _ := pullback.fst _ _ /-- Second projection from the intersection of two pre-`0`-hypercovers. -/ @[simps] noncomputable def interSnd : Hom (inter E F) F where s₀ i := i.2 h₀ _ := pullback.snd _ _ w₀ i := by simp [← pullback.condition] variable {E F} in /-- Universal property of the intersection of two pre-`0`-hypercovers. -/ @[simps] noncomputable def interLift (f : G.Hom E) (g : G.Hom F) : G.Hom (E.inter F) where s₀ i := ⟨f.s₀ i, g.s₀ i⟩ h₀ i := pullback.lift (f.h₀ i) (g.h₀ i) (by simp) end end PreZeroHypercover /-- The pre-`0`-hypercover associated to a presieve `R`. It is indexed by the morphisms in `R`. -/ @[simps -isSimp] def Presieve.preZeroHypercover {S : C} (R : Presieve S) : PreZeroHypercover.{max u v} S where I₀ := R.uncurry X i := i.1.1 f i := i.1.2 @[simp] lemma Presieve.presieve₀_preZeroHypercover {S : C} (R : Presieve S) : R.preZeroHypercover.presieve₀ = R := by refine le_antisymm ?_ ?_ · rintro - - ⟨i⟩ exact i.2 · intro Y f h let i : R.uncurry := ⟨⟨Y, f⟩, h⟩ exact .mk i lemma Presieve.exists_eq_preZeroHypercover {S : C} (R : Presieve S) : ∃ (E : PreZeroHypercover.{max u v} S), R = E.presieve₀ := ⟨R.preZeroHypercover, by simp⟩ /-- The deduplication of a pre-`0`-hypercover `E` in universe `w` to a pre-`0`-hypercover in universe `max u v`. This is indexed by the morphisms of `E`. -/ @[simps! -isSimp] def PreZeroHypercover.shrink {S : C} (E : PreZeroHypercover.{w} S) : PreZeroHypercover.{max u v} S := E.presieve₀.preZeroHypercover @[simp] lemma PreZeroHypercover.presieve₀_shrink {S : C} (E : PreZeroHypercover.{w} S) : E.shrink.presieve₀ = E.presieve₀ := E.presieve₀.presieve₀_preZeroHypercover lemma PreZeroHypercover.shrink_eq_shrink_of_presieve₀_eq_presieve₀ {S : C} {E F : PreZeroHypercover.{w} S} (h : E.presieve₀ = F.presieve₀) : E.shrink = F.shrink := by rw [shrink, shrink, h] lemma PreZeroHypercover.presieve₀_eq_presieve₀_iff {S : C} {E F : PreZeroHypercover.{w} S} : E.presieve₀ = F.presieve₀ ↔ E.shrink = F.shrink := by refine ⟨fun h ↦ shrink_eq_shrink_of_presieve₀_eq_presieve₀ h, fun h ↦ ?_⟩ rw [← E.presieve₀_shrink, ← F.presieve₀_shrink, h] /-- `E` refines its deduplication. -/ def PreZeroHypercover.toShrink {S : C} (E : PreZeroHypercover.{w} S) : E.Hom E.shrink where s₀ i := ⟨⟨_, E.f i⟩, .mk i⟩ h₀ i := 𝟙 _ /-- The deduplication of `E` refines `E`. -/ noncomputable def PreZeroHypercover.fromShrink {S : C} (E : PreZeroHypercover.{w} S) : E.shrink.Hom E where s₀ i := (Presieve.ofArrows_surj _ _ i.2).choose h₀ i := eqToHom (Presieve.ofArrows_surj _ _ i.2).choose_spec.1.symm w₀ i := (Presieve.ofArrows_surj _ _ i.2).choose_spec.2.symm namespace Precoverage variable {J : Precoverage C} /-- The type of `0`-hypercovers of an object `S : C` in a category equipped with a coverage `J`. This can be constructed from a covering of `S`. -/ structure ZeroHypercover (J : Precoverage C) (S : C) extends PreZeroHypercover.{w} S where mem₀ : toPreZeroHypercover.presieve₀ ∈ J S namespace ZeroHypercover variable {S T : C} /-- The `0`-hypercover defined by a single covering morphism. -/ @[simps toPreZeroHypercover] def singleton (f : S ⟶ T) (hf : Presieve.singleton f ∈ J T) : J.ZeroHypercover T where __ := PreZeroHypercover.singleton f mem₀ := by simpa [PreZeroHypercover.presieve₀, PreZeroHypercover.singleton, Presieve.ofArrows_pUnit] /-- Pullback of a `0`-hypercover along a morphism. The components are `pullback f (E.f i)`. -/ @[simps toPreZeroHypercover] noncomputable def pullback₁ [J.IsStableUnderBaseChange] (f : S ⟶ T) (E : ZeroHypercover.{w} J T) [∀ i, HasPullback f (E.f i)] : J.ZeroHypercover S where __ := E.toPreZeroHypercover.pullback₁ f mem₀ := J.mem_coverings_of_isPullback E.f E.mem₀ f _ (fun _ ↦ pullback.snd _ _) fun i ↦ IsPullback.of_hasPullback f (E.f i) /-- Pullback of a `0`-hypercover along a morphism. The components are `pullback (E.f i) f`. -/ @[simps toPreZeroHypercover] noncomputable def pullback₂ [J.IsStableUnderBaseChange] (f : S ⟶ T) (E : ZeroHypercover.{w} J T) [∀ i, HasPullback (E.f i) f] : J.ZeroHypercover S where __ := E.toPreZeroHypercover.pullback₂ f mem₀ := J.mem_coverings_of_isPullback E.f E.mem₀ f _ (fun _ ↦ pullback.fst _ _) fun i ↦ (IsPullback.of_hasPullback (E.f i) f).flip /-- Refining each component of a `0`-hypercover yields a refined `0`-hypercover of the base. -/ @[simps toPreZeroHypercover] def bind [J.IsStableUnderComposition] (E : ZeroHypercover.{w} J T) (F : ∀ i, ZeroHypercover.{w'} J (E.X i)) : ZeroHypercover.{max w w'} J T where __ := E.toPreZeroHypercover.bind (fun i ↦ (F i).toPreZeroHypercover) mem₀ := comp_mem_coverings (f := E.f) (g := fun i j ↦ (F i).f j) E.mem₀ (fun i ↦ (F i).mem₀) /-- Pairwise intersection of two `0`-hypercovers. -/ @[simps toPreZeroHypercover] noncomputable def inter [J.IsStableUnderBaseChange] [J.IsStableUnderComposition] (E : ZeroHypercover.{w} J T) (F : ZeroHypercover.{w'} J T) [∀ i j, HasPullback (E.f i) (F.f j)] : ZeroHypercover.{max w w'} J T where __ := E.toPreZeroHypercover.inter F.toPreZeroHypercover mem₀ := by rw [PreZeroHypercover.inter_def, PreZeroHypercover.presieve₀_reindex] exact (E.bind (fun i ↦ F.pullback₁ (E.f i))).mem₀ /-- Replace the indexing type of a `0`-hypercover. -/ @[simps toPreZeroHypercover] def reindex (E : ZeroHypercover.{w} J T) {ι : Type w'} (e : ι ≃ E.I₀) : ZeroHypercover.{w'} J T where __ := E.toPreZeroHypercover.reindex e mem₀ := by simp [E.mem₀] /-- Disjoint union of two `0`-hypercovers. -/ @[simps toPreZeroHypercover] def sum [J.IsStableUnderSup] (E : ZeroHypercover.{w} J S) (F : ZeroHypercover.{w'} J S) : ZeroHypercover.{max w w'} J S where __ := E.toPreZeroHypercover.sum F.toPreZeroHypercover mem₀ := by rw [PreZeroHypercover.presieve₀_sum] exact J.sup_mem_coverings E.mem₀ F.mem₀ /-- Add a single morphism to a `0`-hypercover. -/ @[simps toPreZeroHypercover] def add (E : ZeroHypercover.{w} J S) {T : C} (f : T ⟶ S) (hf : E.presieve₀ ⊔ Presieve.singleton f ∈ J S) : ZeroHypercover.{w} J S where __ := E.toPreZeroHypercover.add f mem₀ := by rwa [PreZeroHypercover.presieve₀_add] /-- If `L` is a finer precoverage than `K`, any `0`-hypercover wrt. `K` is in particular a `0`-hypercover wrt. to `L`. -/ @[simps toPreZeroHypercover] def weaken {K L : Precoverage C} {X : C} (E : Precoverage.ZeroHypercover K X) (h : K ≤ L) : Precoverage.ZeroHypercover L X where __ := E mem₀ := h _ E.mem₀ instance (K : Precoverage C) [K.HasPullbacks] {X Y : C} (E : K.ZeroHypercover X) (f : Y ⟶ X) : E.presieve₀.HasPullbacks f := K.hasPullbacks_of_mem _ E.mem₀ instance {X Y : C} (E : PreZeroHypercover X) (f : Y ⟶ X) [E.presieve₀.HasPullbacks f] (i : E.I₀) : HasPullback (E.f i) f := E.presieve₀.hasPullback f ⟨i⟩ instance {X Y : C} (E : PreZeroHypercover X) (f : Y ⟶ X) [E.presieve₀.HasPullbacks f] (i : E.I₀) : HasPullback f (E.f i) := hasPullback_symmetry (E.f i) f variable (J) in /-- A morphism of `0`-hypercovers is a morphism of the underlying pre-`0`-hypercovers. -/ abbrev Hom (E : ZeroHypercover.{w} J S) (F : ZeroHypercover.{w'} J S) := E.toPreZeroHypercover.Hom F.toPreZeroHypercover @[simps! id_s₀ id_h₀ comp_s₀ comp_h₀] instance : Category (ZeroHypercover.{w} J S) where Hom := Hom J id _ := PreZeroHypercover.Hom.id _ comp := PreZeroHypercover.Hom.comp /-- An isomorphism in `0`-hypercovers is an isomorphism of the underlying pre-`0`-hypercovers. -/ @[simps] def isoMk {E F : ZeroHypercover.{w} J S} (e : E.toPreZeroHypercover ≅ F.toPreZeroHypercover) : E ≅ F where hom := e.hom inv := e.inv hom_inv_id := e.hom_inv_id inv_hom_id := e.inv_hom_id section Functoriality variable {D : Type*} [Category D] {F : C ⥤ D} {K : Precoverage D} /-- The image of a `0`-hypercover under a functor. -/ @[simps toPreZeroHypercover] def map (F : C ⥤ D) (E : ZeroHypercover.{w} J S) (h : J ≤ K.comap F) : ZeroHypercover.{w} K (F.obj S) where __ := E.toPreZeroHypercover.map F mem₀ := by rw [PreZeroHypercover.presieve₀_map, ← mem_comap_iff] exact h _ E.mem₀ end Functoriality /-- A `w`-`0`-hypercover `E` is `w'`-small if there exists an indexing type `ι` in `Type w'` and a restriction map `ι → E.I₀` such that the restriction of `E` to `ι` is still covering. Note: This is weaker than `E.I₀` being `w'`-small. For example, every Zariski cover of `X : Scheme.{u}` is `u`-small, because `X` itself suffices as indexing type. -/ protected class Small (E : ZeroHypercover.{w} J S) where exists_restrictIndex_mem (E) : ∃ (ι : Type w') (f : ι → E.I₀), (E.restrictIndex f).presieve₀ ∈ J S instance (E : ZeroHypercover.{w} J S) [Small.{w'} E.I₀] : ZeroHypercover.Small.{w'} E where exists_restrictIndex_mem := ⟨_, (equivShrink E.I₀).symm, by simp [E.mem₀]⟩ /-- The `w'`-index type of a `w'`-small `0`-hypercover. -/ def Small.Index (E : ZeroHypercover.{w} J S) [ZeroHypercover.Small.{w'} E] : Type w' := (Small.exists_restrictIndex_mem E).choose /-- The index restriction function of a small `0`-hypercover. -/ noncomputable def Small.restrictFun (E : ZeroHypercover.{w} J S) [ZeroHypercover.Small.{w'} E] : Index E → E.I₀ := (Small.exists_restrictIndex_mem E).choose_spec.choose lemma Small.mem₀ (E : ZeroHypercover.{w} J S) [ZeroHypercover.Small.{w'} E] : (E.restrictIndex <| Small.restrictFun E).presieve₀ ∈ J S := (Small.exists_restrictIndex_mem E).choose_spec.choose_spec instance (E : ZeroHypercover.{w} J S) : ZeroHypercover.Small.{max u v} E where exists_restrictIndex_mem := by obtain ⟨ι, Y, f, h⟩ := E.presieve₀.exists_eq_ofArrows have (Z : C) (g : Z ⟶ S) (hg : Presieve.ofArrows Y f g) : ∃ (j : E.I₀) (h : Z = E.X j), g = eqToHom h ≫ E.f j := by obtain ⟨j⟩ : E.presieve₀ g := by rwa [h] use j, rfl simp choose j h₁ h₂ using this refine ⟨ι, fun i ↦ j _ _ (.mk i), ?_⟩ convert E.mem₀ exact le_antisymm (fun Z g ⟨i⟩ ↦ ⟨_⟩) (h ▸ fun Z g ⟨i⟩ ↦ .mk' i (h₁ _ _ _) (h₂ _ _ _)) /-- Restrict a `w'`-small `0`-hypercover to a `w'`-`0`-hypercover. -/ @[simps toPreZeroHypercover] noncomputable def restrictIndexOfSmall (E : ZeroHypercover.{w} J S) [ZeroHypercover.Small.{w'} E] : ZeroHypercover.{w'} J S where __ := E.toPreZeroHypercover.restrictIndex (Small.restrictFun E) mem₀ := Small.mem₀ E instance (E : ZeroHypercover.{w} J S) [ZeroHypercover.Small.{w'} E] {T : C} (f : T ⟶ S) [IsStableUnderBaseChange J] [∀ (i : E.I₀), HasPullback f (E.f i)] : ZeroHypercover.Small.{w'} (E.pullback₁ f) := by use Small.Index E, Small.restrictFun E have _ (i) : HasPullback f (E.restrictIndexOfSmall.f i) := by dsimp; infer_instance exact ((restrictIndexOfSmall.{w'} E).pullback₁ f).mem₀ end ZeroHypercover lemma mem_iff_exists_zeroHypercover {X : C} {R : Presieve X} : R ∈ J X ↔ ∃ (𝒰 : ZeroHypercover.{max u v} J X), R = Presieve.ofArrows 𝒰.X 𝒰.f := by refine ⟨fun hR ↦ ?_, fun ⟨𝒰, hR⟩ ↦ hR ▸ 𝒰.mem₀⟩ obtain ⟨ι, Y, f, rfl⟩ := R.exists_eq_ofArrows use ⟨⟨ι, Y, f⟩, hR⟩ lemma le_of_zeroHypercover {J K : Precoverage C} (h : ∀ ⦃X : C⦄ ⦃E : ZeroHypercover.{max u v} J X⦄, E.presieve₀ ∈ K X) : J ≤ K := by intro X R hR obtain ⟨E, rfl⟩ := R.exists_eq_preZeroHypercover exact h (E := ⟨E, hR⟩) /-- A precoverage is `w`-small, if every `0`-hypercover is `w`-small. -/ class Small (J : Precoverage C) : Prop where zeroHypercoverSmall : ∀ {S : C} (E : ZeroHypercover.{max u v} J S), ZeroHypercover.Small.{w'} E instance (J : Precoverage C) [Small.{w} J] {S : C} (E : ZeroHypercover.{w'} J S) : ZeroHypercover.Small.{w} E := by have : ZeroHypercover.Small.{w} (ZeroHypercover.restrictIndexOfSmall.{max u v} E) := Small.zeroHypercoverSmall _ let E' := ZeroHypercover.restrictIndexOfSmall.{w} (ZeroHypercover.restrictIndexOfSmall.{max u v} E) use E'.I₀, ZeroHypercover.Small.restrictFun _ ∘ ZeroHypercover.Small.restrictFun _ exact E'.mem₀ end Precoverage end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/Hypercover/Homotopy.lean
import Mathlib.CategoryTheory.Quotient import Mathlib.CategoryTheory.Sites.Hypercover.One import Mathlib.CategoryTheory.Filtered.Basic /-! # The category of `1`-hypercovers up to homotopy In this file we define the category of `1`-hypercovers up to homotopy. This is the category of `1`-hypercovers, but where morphisms are considered up to existence of a homotopy. ## Main definitions - `CategoryTheory.PreOneHypercover.Homotopy`: A homotopy of refinements `E ⟶ F` is a family of morphisms `Xᵢ ⟶ Yₐ` where `Yₐ` is a component of the cover of `X_{f(i)} ×[S] X_{g(i)}`. - `CategoryTheory.GrothendieckTopology.HOneHypercover`: The category of `1`-hypercovers with respect to a Grothendieck topology and morphisms up to homotopy. ## Main results - `CategoryTheory.GrothendieckTopology.HOneHypercover.isCofiltered_of_hasPullbacks`: The category of `1`-hypercovers up to homotopy is cofiltered if `C` has pullbacks. -/ universe w'' w' w v u namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] namespace PreOneHypercover variable {S : C} {E : PreOneHypercover.{w} S} {F : PreOneHypercover.{w'} S} /-- A homotopy of refinements `E ⟶ F` is a family of morphisms `Xᵢ ⟶ Yₐ` where `Yₐ` is a component of the cover of `X_{f(i)} ×[S] X_{g(i)}`. -/ structure Homotopy (f g : E.Hom F) where /-- The index map sending `i : E.I₀` to `a` above `(f(i), g(i))`. -/ H (i : E.I₀) : F.I₁ (f.s₀ i) (g.s₀ i) /-- The morphism `Xᵢ ⟶ Yₐ`. -/ a (i : E.I₀) : E.X i ⟶ F.Y (H i) wl (i : E.I₀) : a i ≫ F.p₁ (H i) = f.h₀ i wr (i : E.I₀) : a i ≫ F.p₂ (H i) = g.h₀ i attribute [reassoc (attr := simp)] Homotopy.wl Homotopy.wr /-- Homotopic refinements induce the same map on multiequalizers. -/ lemma Homotopy.mapMultiforkOfIsLimit_eq {A : Type*} [Category A] {E F : PreOneHypercover.{w} S} {f g : E.Hom F} (H : Homotopy f g) (P : Cᵒᵖ ⥤ A) {c : Multifork (E.multicospanIndex P)} (hc : IsLimit c) (d : Multifork (F.multicospanIndex P)) : f.mapMultiforkOfIsLimit P hc d = g.mapMultiforkOfIsLimit P hc d := by refine Multifork.IsLimit.hom_ext hc fun a ↦ ?_ have heq := d.condition ⟨⟨(f.s₀ a), (g.s₀ a)⟩, H.H a⟩ simp only [multicospanIndex_right, multicospanShape_fst, multicospanIndex_left, multicospanIndex_fst, multicospanShape_snd, multicospanIndex_snd] at heq simp [-Homotopy.wl, -Homotopy.wr, ← H.wl, ← H.wr, reassoc_of% heq] variable [Limits.HasPullbacks C] (f g : E.Hom F) /-- (Implementation): The covering object of `cylinder f g`. -/ noncomputable abbrev cylinderX {i : E.I₀} (k : F.I₁ (f.s₀ i) (g.s₀ i)) : C := pullback (pullback.lift (f.h₀ i) (g.h₀ i) (by simp)) (F.toPullback k) /-- (Implementation): The structure morphisms of the covering objects of `cylinder f g`. -/ noncomputable abbrev cylinderf {i : E.I₀} (k : F.I₁ (f.s₀ i) (g.s₀ i)) : cylinderX f g k ⟶ S := pullback.fst _ _ ≫ E.f _ /-- Given two refinement morphisms `f, g : E ⟶ F`, this is a (pre-)`1`-hypercover `W` that admits a morphism `h : W ⟶ E` such that `h ≫ f` and `h ≫ g` are homotopic. Hence they become equal after quotienting out by homotopy. This is a `1`-hypercover, if `E` and `F` are (see `OneHypercover.cylinder`). -/ @[simps] noncomputable def cylinder (f g : E.Hom F) : PreOneHypercover.{max w w'} S where I₀ := Σ (i : E.I₀), F.I₁ (f.s₀ i) (g.s₀ i) X p := cylinderX f g p.2 f p := cylinderf f g p.2 I₁ p q := ULift.{max w w'} (E.I₁ p.1 q.1) Y {p q} k := pullback (pullback.map (cylinderf f g p.2) (cylinderf f g q.2) _ _ (pullback.fst _ _) (pullback.fst _ _) (𝟙 S) (by simp) (by simp)) (pullback.lift _ _ (E.w k.down)) p₁ {p q} k := pullback.fst _ _ ≫ pullback.fst _ _ p₂ {p q} k := pullback.fst _ _ ≫ pullback.snd _ _ w {_ _} k := by simp [pullback.condition] lemma toPullback_cylinder {i j : (cylinder f g).I₀} (k : (cylinder f g).I₁ i j) : (cylinder f g).toPullback k = pullback.fst _ _ := by apply pullback.hom_ext <;> simp [toPullback] lemma sieve₀_cylinder : (cylinder f g).sieve₀ = Sieve.generate (Presieve.bindOfArrows _ E.f <| fun i ↦ (Sieve.pullback (pullback.lift (f.h₀ _) (g.h₀ _) (by simp)) (F.sieve₁' _ _)).arrows) := by refine le_antisymm ?_ ?_ · rw [PreZeroHypercover.sieve₀, Sieve.generate_le_iff] rintro - - ⟨i⟩ refine ⟨_, 𝟙 _, (cylinder f g).f _, ⟨_, _, ?_⟩, by simp⟩ simp only [Sieve.pullback_apply, pullback.condition] exact Sieve.downward_closed _ (Sieve.ofArrows_mk _ _ _) _ · rw [Sieve.generate_le_iff, PreZeroHypercover.sieve₀] rintro Z u ⟨i, v, ⟨W, o, o', ⟨j⟩, hoo'⟩⟩ exact ⟨_, pullback.lift v o hoo'.symm, (cylinder f g).f ⟨i, j⟩, Presieve.ofArrows.mk _, by simp⟩ lemma sieve₁'_cylinder (i j : Σ (i : E.I₀), F.I₁ (f.s₀ i) (g.s₀ i)) : (cylinder f g).sieve₁' i j = Sieve.pullback (pullback.map _ _ _ _ (pullback.fst _ _) (pullback.fst _ _) (𝟙 S) (by simp) (by simp)) (E.sieve₁' i.1 j.1) := by refine le_antisymm ?_ ?_ · rw [sieve₁', Sieve.ofArrows, Sieve.generate_le_iff] rintro - - ⟨k⟩ refine ⟨E.Y k.down, pullback.snd _ _, E.toPullback k.down, Presieve.ofArrows.mk k.down, ?_⟩ simp only [cylinder_Y, cylinder_f, toPullback_cylinder, pullback.condition] · rw [sieve₁', Sieve.ofArrows, ← Sieve.pullbackArrows_comm, Sieve.generate_le_iff] rintro Z u ⟨W, v, ⟨k⟩⟩ simp_rw [← pullbackSymmetry_inv_comp_fst] apply (((cylinder f g).sieve₁' i j)).downward_closed rw [sieve₁'] convert Sieve.ofArrows_mk _ _ (ULift.up k) simp [toPullback_cylinder f g ⟨k⟩] /-- (Implementation): The refinement morphism `cylinder f g ⟶ E`. -/ @[simps] noncomputable def cylinderHom : (cylinder f g).Hom E where s₀ p := p.1 s₁ k := k.down h₀ p := pullback.fst _ _ h₁ {p q} k := pullback.snd _ _ w₁₁ k := by have : E.p₁ k.down = pullback.lift _ _ (E.w k.down) ≫ pullback.fst _ _ := by simp nth_rw 2 [this] rw [← pullback.condition_assoc] simp w₁₂ {p q} k := by have : E.p₂ k.down = pullback.lift _ _ (E.w k.down) ≫ pullback.snd _ _ := by simp nth_rw 2 [this] rw [← pullback.condition_assoc] simp w₀ := by simp /-- (Implementation): The homotopy of the morphisms `cylinder f g ⟶ E ⟶ F`. -/ noncomputable def cylinderHomotopy : Homotopy ((cylinderHom f g).comp f) ((cylinderHom f g).comp g) where H p := p.2 a p := pullback.snd _ _ wl p := by have : F.p₁ p.snd = pullback.lift _ _ (F.w p.2) ≫ pullback.fst _ _ := by simp nth_rw 1 [this] rw [← pullback.condition_assoc] simp wr p := by have : g.h₀ p.fst = pullback.lift (f.h₀ p.fst) (g.h₀ p.fst) (by simp) ≫ pullback.snd (F.f _) (F.f _) := by simp dsimp only [cylinder_X, Hom.comp_s₀, cylinder_I₀, Function.comp_apply, cylinderHom_s₀, Hom.comp_h₀, cylinderHom_h₀] nth_rw 3 [this] rw [pullback.condition_assoc] simp /-- Up to homotopy, the category of (pre-)`1`-hypercovers is cofiltered. -/ lemma exists_nonempty_homotopy (f g : E.Hom F) : ∃ (W : PreOneHypercover.{max w w'} S) (h : W.Hom E), Nonempty (Homotopy (h.comp f) (h.comp g)) := ⟨cylinder f g, PreOneHypercover.cylinderHom f g, ⟨cylinderHomotopy f g⟩⟩ end PreOneHypercover namespace GrothendieckTopology open PreOneHypercover OneHypercover variable {J : GrothendieckTopology C} namespace OneHypercover variable {S : C} {E : OneHypercover.{w} J S} {F : OneHypercover.{w'} J S} variable [HasPullbacks C] /-- Given two refinement morphism `f, g : E ⟶ F`, this is a `1`-hypercover `W` that admits a morphism `h : W ⟶ E` such that `h ≫ f` and `h ≫ g` are homotopic. Hence they become equal after quotienting out by homotopy. -/ @[simps! toPreOneHypercover] noncomputable def cylinder (f g : E.Hom F) : J.OneHypercover S := mk' (PreOneHypercover.cylinder f g) (by rw [PreOneHypercover.sieve₀_cylinder] refine J.bindOfArrows E.mem₀ fun i ↦ ?_ rw [Sieve.generate_sieve] exact J.pullback_stable _ (mem_sieve₁' F _ _)) (fun i j ↦ by rw [PreOneHypercover.sieve₁'_cylinder] exact J.pullback_stable _ (mem_sieve₁' E _ _)) /-- Up to homotopy, the category of `1`-hypercovers is cofiltered. -/ lemma exists_nonempty_homotopy (f g : E.Hom F) : ∃ (W : OneHypercover.{max w w'} J S) (h : W.Hom E), Nonempty (PreOneHypercover.Homotopy (h.comp f) (h.comp g)) := ⟨cylinder f g, PreOneHypercover.cylinderHom f g, ⟨PreOneHypercover.cylinderHomotopy f g⟩⟩ end OneHypercover variable (J S) /-- Two refinement morphisms of `1`-hypercovers are homotopic if there exists a homotopy between them. Note: This is not an equivalence relation, it is not even reflexive! -/ def OneHypercover.homotopicRel : HomRel (J.OneHypercover S) := fun _ _ f g ↦ Nonempty (PreOneHypercover.Homotopy f g) /-- The category of `1`-hypercovers with refinement morphisms up to homotopy. -/ abbrev HOneHypercover (S : C) := Quotient (OneHypercover.homotopicRel J S) /-- The canonical projection from `1`-hypercovers to `1`-hypercovers up to homotopy. -/ abbrev OneHypercover.toHOneHypercover (S : C) : J.OneHypercover S ⥤ J.HOneHypercover S := Quotient.functor _ lemma _root_.CategoryTheory.PreOneHypercover.Homotopy.map_eq_map {S : C} {E F : J.OneHypercover S} {f g : E ⟶ F} (H : Homotopy f g) : (toHOneHypercover J S).map f = (toHOneHypercover J S).map g := Quotient.sound _ ⟨H⟩ namespace HOneHypercover variable {S : C} instance : Nonempty (J.HOneHypercover S) := ⟨⟨Nonempty.some inferInstance⟩⟩ /-- If `C` has pullbacks, the category of `1`-hypercovers up to homotopy is cofiltered. -/ instance isCofiltered_of_hasPullbacks [HasPullbacks C] : IsCofiltered (J.HOneHypercover S) where cone_objs {E F} := ⟨⟨E.1.inter F.1⟩, Quot.mk _ (PreOneHypercover.interFst _ _), Quot.mk _ (PreOneHypercover.interSnd _ _), ⟨⟩⟩ cone_maps {X Y} f g := by obtain ⟨(f : X.1 ⟶ Y.1), rfl⟩ := (toHOneHypercover J S).map_surjective f obtain ⟨(g : X.1 ⟶ Y.1), rfl⟩ := (toHOneHypercover J S).map_surjective g obtain ⟨W, h, ⟨H⟩⟩ := OneHypercover.exists_nonempty_homotopy f g use (toHOneHypercover J S).obj W, (toHOneHypercover J S).map h rw [← Functor.map_comp, ← Functor.map_comp] exact H.map_eq_map end HOneHypercover end GrothendieckTopology end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sites/NonabelianCohomology/H1.lean
import Mathlib.Algebra.Category.Grp.Basic /-! The cohomology of a sheaf of groups in degree 1 In this file, we shall define the cohomology in degree 1 of a sheaf of groups (TODO). Currently, given a presheaf of groups `G : Cᵒᵖ ⥤ GrpCat` and a family of objects `U : I → C`, we define 1-cochains/1-cocycles/H^1 with values in `G` over `U`. (This definition neither requires the assumption that `G` is a sheaf, nor that `U` covers the terminal object.) As we do not assume that `G` is a presheaf of abelian groups, this cohomology theory is only defined in low degrees; in the abelian case, it would be a particular case of Čech cohomology (TODO). ## TODO * show that if `1 ⟶ G₁ ⟶ G₂ ⟶ G₃ ⟶ 1` is a short exact sequence of sheaves of groups, and `x₃` is a global section of `G₃` which can be locally lifted to a section of `G₂`, there is an associated canonical cohomology class of `G₁` which is trivial iff `x₃` can be lifted to a global section of `G₂`. (This should hold more generally if `G₂` is a sheaf of sets on which `G₁` acts freely, and `G₃` is the quotient sheaf.) * deduce a similar result for abelian sheaves * when the notion of quasi-coherent sheaves on schemes is defined, show that if `0 ⟶ Q ⟶ M ⟶ N ⟶ 0` is an exact sequence of abelian sheaves over a scheme `X` and `Q` is the underlying sheaf of a quasi-coherent sheaf, then `M(U) ⟶ N(U)` is surjective for any affine open `U`. * take the colimit of `OneCohomology G U` over all covering families `U` (for a Grothendieck topology) # References * [J. Frenkel, *Cohomologie non abélienne et espaces fibrés*][frenkel1957] -/ universe w' w v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] namespace PresheafOfGroups variable (G : Cᵒᵖ ⥤ GrpCat.{w}) {I : Type w'} (U : I → C) /-- A zero cochain consists of a family of sections. -/ def ZeroCochain := ∀ (i : I), G.obj (Opposite.op (U i)) instance : Group (ZeroCochain G U) := Pi.group namespace Cochain₀ @[simp] lemma one_apply (i : I) : (1 : ZeroCochain G U) i = 1 := rfl @[simp] lemma inv_apply (γ : ZeroCochain G U) (i : I) : γ⁻¹ i = (γ i)⁻¹ := rfl @[simp] lemma mul_apply (γ₁ γ₂ : ZeroCochain G U) (i : I) : (γ₁ * γ₂) i = γ₁ i * γ₂ i := rfl end Cochain₀ /-- A 1-cochain of a presheaf of groups `G : Cᵒᵖ ⥤ GrpCat` on a family `U : I → C` of objects consists of the data of an element in `G.obj (Opposite.op T)` whenever we have elements `i` and `j` in `I` and maps `a : T ⟶ U i` and `b : T ⟶ U j`, and it must satisfy a compatibility with respect to precomposition. (When the binary product of `U i` and `U j` exists, this data for all `T`, `a` and `b` corresponds to the data of a section of `G` on this product.) -/ @[ext] structure OneCochain where /-- the data involved in a 1-cochain -/ ev (i j : I) ⦃T : C⦄ (a : T ⟶ U i) (b : T ⟶ U j) : G.obj (Opposite.op T) ev_precomp (i j : I) ⦃T T' : C⦄ (φ : T ⟶ T') (a : T' ⟶ U i) (b : T' ⟶ U j) : G.map φ.op (ev i j a b) = ev i j (φ ≫ a) (φ ≫ b) := by aesop namespace OneCochain attribute [simp] OneCochain.ev_precomp instance : One (OneCochain G U) where one := { ev := fun _ _ _ _ _ ↦ 1 } @[simp] lemma one_ev (i j : I) {T : C} (a : T ⟶ U i) (b : T ⟶ U j) : (1 : OneCochain G U).ev i j a b = 1 := rfl variable {G U} instance : Mul (OneCochain G U) where mul γ₁ γ₂ := { ev := fun i j _ a b ↦ γ₁.ev i j a b * γ₂.ev i j a b } @[simp] lemma mul_ev (γ₁ γ₂ : OneCochain G U) (i j : I) {T : C} (a : T ⟶ U i) (b : T ⟶ U j) : (γ₁ * γ₂).ev i j a b = γ₁.ev i j a b * γ₂.ev i j a b := rfl instance : Inv (OneCochain G U) where inv γ := { ev := fun i j _ a b ↦ (γ.ev i j a b) ⁻¹} @[simp] lemma inv_ev (γ : OneCochain G U) (i j : I) {T : C} (a : T ⟶ U i) (b : T ⟶ U j) : (γ⁻¹).ev i j a b = (γ.ev i j a b)⁻¹ := rfl instance : Group (OneCochain G U) where mul_assoc _ _ _ := by ext; apply mul_assoc one_mul _ := by ext; apply one_mul mul_one _ := by ext; apply mul_one inv_mul_cancel _ := by ext; apply inv_mul_cancel end OneCochain /-- A 1-cocycle is a 1-cochain which satisfies the cocycle condition. -/ structure OneCocycle extends OneCochain G U where ev_trans (i j k : I) ⦃T : C⦄ (a : T ⟶ U i) (b : T ⟶ U j) (c : T ⟶ U k) : ev i j a b * ev j k b c = ev i k a c := by aesop namespace OneCocycle instance : One (OneCocycle G U) where one := OneCocycle.mk 1 @[simp] lemma one_toOneCochain : (1 : OneCocycle G U).toOneCochain = 1 := rfl @[simp] lemma ev_refl (γ : OneCocycle G U) (i : I) ⦃T : C⦄ (a : T ⟶ U i) : γ.ev i i a a = 1 := by simpa using γ.ev_trans i i i a a a lemma ev_symm (γ : OneCocycle G U) (i j : I) ⦃T : C⦄ (a : T ⟶ U i) (b : T ⟶ U j) : γ.ev i j a b = (γ.ev j i b a)⁻¹ := by rw [← mul_left_inj (γ.ev j i b a), γ.ev_trans i j i a b a, ev_refl, inv_mul_cancel] end OneCocycle variable {G U} /-- The assertion that two cochains in `OneCochain G U` are cohomologous via an explicit zero-cochain. -/ def OneCohomologyRelation (γ₁ γ₂ : OneCochain G U) (α : ZeroCochain G U) : Prop := ∀ (i j : I) ⦃T : C⦄ (a : T ⟶ U i) (b : T ⟶ U j), G.map a.op (α i) * γ₁.ev i j a b = γ₂.ev i j a b * G.map b.op (α j) namespace OneCohomologyRelation lemma refl (γ : OneCochain G U) : OneCohomologyRelation γ γ 1 := fun _ _ _ _ _ ↦ by simp lemma symm {γ₁ γ₂ : OneCochain G U} {α : ZeroCochain G U} (h : OneCohomologyRelation γ₁ γ₂ α) : OneCohomologyRelation γ₂ γ₁ α⁻¹ := fun i j T a b ↦ by rw [← mul_left_inj (G.map b.op (α j)), mul_assoc, ← h i j a b, mul_assoc, Cochain₀.inv_apply, map_inv, inv_mul_cancel_left, Cochain₀.inv_apply, map_inv, inv_mul_cancel, mul_one] lemma trans {γ₁ γ₂ γ₃ : OneCochain G U} {α β : ZeroCochain G U} (h₁₂ : OneCohomologyRelation γ₁ γ₂ α) (h₂₃ : OneCohomologyRelation γ₂ γ₃ β) : OneCohomologyRelation γ₁ γ₃ (β * α) := fun i j T a b ↦ by dsimp rw [map_mul, map_mul, mul_assoc, h₁₂ i j a b, ← mul_assoc, h₂₃ i j a b, mul_assoc] end OneCohomologyRelation namespace OneCocycle /-- The cohomology (equivalence) relation on 1-cocycles. -/ def IsCohomologous (γ₁ γ₂ : OneCocycle G U) : Prop := ∃ (α : ZeroCochain G U), OneCohomologyRelation γ₁.toOneCochain γ₂.toOneCochain α variable (G U) lemma equivalence_isCohomologous : _root_.Equivalence (IsCohomologous (G := G) (U := U)) where refl γ := ⟨_, OneCohomologyRelation.refl γ.toOneCochain⟩ symm := by rintro γ₁ γ₂ ⟨α, h⟩ exact ⟨_, h.symm⟩ trans := by rintro γ₁ γ₂ γ₂ ⟨α, h⟩ ⟨β, h'⟩ exact ⟨_, h.trans h'⟩ end OneCocycle variable (G U) in /-- The cohomology in degree 1 of a presheaf of groups `G : Cᵒᵖ ⥤ GrpCat` on a family of objects `U : I → C`. -/ def H1 := Quot (OneCocycle.IsCohomologous (G := G) (U := U)) /-- The cohomology class of a 1-cocycle. -/ def OneCocycle.class (γ : OneCocycle G U) : H1 G U := Quot.mk _ γ instance : One (H1 G U) where one := OneCocycle.class 1 lemma OneCocycle.class_eq_iff (γ₁ γ₂ : OneCocycle G U) : γ₁.class = γ₂.class ↔ γ₁.IsCohomologous γ₂ := (equivalence_isCohomologous _ _ ).quot_mk_eq_iff _ _ lemma OneCocycle.IsCohomologous.class_eq {γ₁ γ₂ : OneCocycle G U} (h : γ₁.IsCohomologous γ₂) : γ₁.class = γ₂.class := Quot.sound h end PresheafOfGroups end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Abelian/Yoneda.lean
import Mathlib.Algebra.Category.Grp.Abelian import Mathlib.CategoryTheory.Abelian.DiagramLemmas.Four import Mathlib.CategoryTheory.Abelian.Projective.Basic import Mathlib.CategoryTheory.Generator.Preadditive import Mathlib.CategoryTheory.Limits.Preserves.Opposites /-! # Fullness of restrictions of `preadditiveCoyonedaObj` In this file we give a sufficient criterion for a restriction of the functor `preadditiveCoyonedaObj G` to be full: this is the case if `C` is an abelian category and `G : C` is a projective separator such that every object in the relevant subcategory is a quotient of `G`. -/ open CategoryTheory Opposite Limits universe v v' u u' variable {C : Type u} [Category.{v} C] [Abelian C] namespace CategoryTheory.Abelian section attribute [local instance] preservesFiniteLimits_op theorem preadditiveCoyonedaObj_map_surjective {G : C} [Projective G] (hG : IsSeparator G) {X : C} (p : G ⟶ X) [Epi p] {Y : C} : Function.Surjective ((preadditiveCoyonedaObj G).map : (X ⟶ Y) → _) := by rw [← Functor.coe_mapAddHom, ← AddCommGrpCat.hom_ofHom (preadditiveCoyonedaObj G).mapAddHom, ← AddCommGrpCat.epi_iff_surjective] let cm : ShortComplex C := ⟨kernel.ι p, p, by simp⟩ have exact : cm.Exact := ShortComplex.exact_of_f_is_kernel _ (kernelIsKernel _) have mono : Mono cm.op.f := by dsimp [cm]; infer_instance let φ := preadditiveCoyonedaObj G have faithful : φ.Faithful := by rwa [← isSeparator_iff_faithful_preadditiveCoyonedaObj] apply ShortComplex.epi_of_mono_of_epi_of_mono (cm.op.mapNatTrans (preadditiveYonedaMap _ _)) · exact exact.op.map_of_mono_of_preservesKernel _ mono inferInstance · simp only [ShortComplex.map_f] infer_instance · suffices φ.map.Surjective by simpa [AddCommGrpCat.epi_iff_surjective, Functor.coe_mapAddHom] exact fun f => ⟨f (𝟙 G), by cat_disch⟩ · simp [AddCommGrpCat.mono_iff_injective, Functor.coe_mapAddHom, Functor.map_injective] end variable {D : Type u'} [Category.{v'} D] (F : D ⥤ C) theorem full_comp_preadditiveCoyonedaObj [F.Full] {G : C} [Projective G] (hG : IsSeparator G) (hG₂ : ∀ X, ∃ (p : G ⟶ F.obj X), Epi p) : (F ⋙ preadditiveCoyonedaObj G).Full where map_surjective {X Y} f := by obtain ⟨p, _⟩ := hG₂ X obtain ⟨f, rfl⟩ := preadditiveCoyonedaObj_map_surjective hG p f obtain ⟨f, rfl⟩ := F.map_surjective f exact ⟨f, rfl⟩ end CategoryTheory.Abelian
.lake/packages/mathlib/Mathlib/CategoryTheory/Abelian/FreydMitchell.lean
import Mathlib.CategoryTheory.Abelian.GrothendieckCategory.ModuleEmbedding.Opposite import Mathlib.CategoryTheory.Abelian.GrothendieckAxioms.Indization /-! # The Freyd-Mitchell embedding theorem Let `C` be an abelian category. We construct a ring `FreydMitchell.EmbeddingRing C` and a functor `FreydMitchell.embedding : C ⥤ ModuleCat.{max u v} (EmbeddingRing C)` which is full, faithful and exact. ## Overview over the proof The usual strategy to prove the Freyd-Mitchell embedding theorem is as follows: 1. Prove that if `D` is a Grothendieck abelian category and `F : C ⥤ Dᵒᵖ` is a functor from a small category, then there is a functor `G : Dᵒᵖ ⥤ ModuleCat R` for a suitable `R` such that `G` is faithful and exact and `F ⋙ G` is full. 2. Find a suitable Grothendieck abelian category `D` and a full, faithful and exact functor `F : C ⥤ Dᵒᵖ`. To prove (1), we proceed as follows: 1. Using the Special Adjoint Functor Theorem and the duality between subobjects and quotients in abelian categories, we have that Grothendieck abelian categories have all limits (this is shown in `Mathlib/CategoryTheory/Abelian/GrothendieckCategory/Basic.lean`). 2. Using the small object argument, it is shown that Grothendieck abelian categories have enough injectives (see `Mathlib/CategoryTheory/Abelian/GrothendieckCategory/EnoughInjectives.lean`). 3. Putting these two together, it follows that Grothendieck abelian categories have an injective cogenerator (see `Mathlib/CategoryTheory/Generator/Abelian.lean`). 4. By taking a coproduct of copies of the injective cogenerator, we find a projective separator `G` in `Dᵒᵖ` such that every object in the image of `F` is a quotient of `G`. Then the additive Hom functor `Hom(G, ·) : Dᵒᵖ ⥤ Module (End G)ᵐᵒᵖ` is faithful (because `G` is a separator), left exact (because it is a hom functor), right exact (because `G` is projective) and full (because of a combination of the aforementioned properties, see `Mathlib/CategoryTheory/Abelian/Yoneda.lean`). We put this all together in the file `Mathlib/CategoryTheory/Abelian/GrothendieckCategory/ModuleEmbedding/Opposite.lean`. To prove (2), there are multiple options. * Some sources (for example Freyd's "Abelian Categories") choose `D := LeftExactFunctor C Ab`. The main difficulty with this approach is that it is not obvious that `D` is abelian. This approach has a very algebraic flavor and requires a relatively large amount of ad-hoc reasoning. * In the Stacks project, it is suggested to choose `D := Sheaf J Ab` for a suitable Grothendieck topology on `Cᵒᵖ` and there are reasons to believe that this `D` is in fact equivalent to `LeftExactFunctor C Ab`. This approach translates many of the interesting properties along the sheafification adjunction from a category of `Ab`-valued presheaves, which in turn inherits many interesting properties from the category of abelian groups. * Kashiwara and Schapira choose `D := Ind Cᵒᵖ`, which can be shown to be equivalent to `LeftExactFunctor C Ab` (see the file `Mathlib/CategoryTheory/Preadditive/Indization.lean`). This approach deduces most interesting properties from the category of types. When work on this theorem commenced in early 2022, all three approaches were quite out of reach. By the time the theorem was proved in early 2025, both the `Sheaf` approach and the `Ind` approach were available in mathlib. The code below uses `D := Ind Cᵒᵖ`. ## Implementation notes In the literature you will generally only find this theorem stated for small categories `C`. In Lean, we can work around this limitation by passing from `C` to `AsSmall.{max u v} C`, thereby enlarging the category of modules that we land in (which should be inconsequential in most applications) so that our embedding theorem applies to all abelian categories. If `C` was already a small category, then this does not change anything. ## References * https://stacks.math.columbia.edu/tag/05PL * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Section 9.6 -/ universe v u open CategoryTheory Limits namespace CategoryTheory.Abelian variable {C : Type u} [Category.{v} C] [Abelian C] namespace FreydMitchell open ZeroObject in instance : Nonempty (AsSmall.{max u v} C) := ⟨0⟩ variable (C) in /-- Given an abelian category `C`, this is a ring such that there is a full, faithful and exact embedding `C ⥤ ModuleCat (EmbeddingRing C)`. It is probably not a good idea to unfold this. -/ def EmbeddingRing : Type (max u v) := IsGrothendieckAbelian.OppositeModuleEmbedding.EmbeddingRing (Ind.yoneda (C := (AsSmall.{max u v} C)ᵒᵖ)).rightOp noncomputable instance : Ring (EmbeddingRing C) := inferInstanceAs <| Ring <| IsGrothendieckAbelian.OppositeModuleEmbedding.EmbeddingRing (Ind.yoneda (C := (AsSmall.{max u v} C)ᵒᵖ)).rightOp variable (C) in private def F : C ⥤ AsSmall.{max u v} C := AsSmall.equiv.functor variable (C) in private noncomputable def G : AsSmall.{max u v} C ⥤ (Ind (AsSmall.{max u v} C)ᵒᵖ)ᵒᵖ := Ind.yoneda.rightOp variable (C) in private noncomputable def H : (Ind (AsSmall.{max u v} C)ᵒᵖ)ᵒᵖ ⥤ ModuleCat.{max u v} (EmbeddingRing C) := IsGrothendieckAbelian.OppositeModuleEmbedding.embedding (G C) variable (C) in /-- This is the full, faithful and exact embedding `C ⥤ ModuleCat (EmbeddingRing C)`. The fact that such a functor exists is called the Freyd-Mitchell embedding theorem. It is probably not a good idea to unfold this. -/ noncomputable def functor : C ⥤ ModuleCat.{max u v} (EmbeddingRing C) := F C ⋙ G C ⋙ H C instance : (functor C).Faithful := by rw [functor] have : (F C).Faithful := by rw [F]; infer_instance have : (G C).Faithful := by rw [G]; infer_instance have : (H C).Faithful := IsGrothendieckAbelian.OppositeModuleEmbedding.faithful_embedding _ infer_instance instance : (functor C).Full := by rw [functor] have : (F C).Full := by rw [F]; infer_instance have : (G C).Full := by rw [G]; infer_instance have : (G C ⋙ H C).Full := IsGrothendieckAbelian.OppositeModuleEmbedding.full_embedding _ infer_instance instance : PreservesFiniteLimits (functor C) := by rw [functor] have : PreservesFiniteLimits (F C) := by rw [F]; infer_instance have : PreservesFiniteLimits (G C) := by rw [G]; apply preservesFiniteLimits_rightOp have : PreservesFiniteLimits (H C) := IsGrothendieckAbelian.OppositeModuleEmbedding.preservesFiniteLimits_embedding _ infer_instance instance : PreservesFiniteColimits (functor C) := by rw [functor] have : PreservesFiniteColimits (F C) := by rw [F]; infer_instance have : PreservesFiniteColimits (G C) := by rw [G]; apply preservesFiniteColimits_rightOp have : PreservesFiniteColimits (H C) := IsGrothendieckAbelian.OppositeModuleEmbedding.preservesFiniteColimits_embedding _ infer_instance end FreydMitchell /-- The Freyd-Mitchell embedding theorem. See also `FreydMitchell.functor` for a functor which has the relevant instances. -/ @[stacks 05PP] theorem freyd_mitchell (C : Type u) [Category.{v} C] [Abelian C] : ∃ (R : Type (max u v)) (_ : Ring R) (F : C ⥤ ModuleCat.{max u v} R), F.Full ∧ F.Faithful ∧ PreservesFiniteLimits F ∧ PreservesFiniteColimits F := ⟨_, _, FreydMitchell.functor C, inferInstance, inferInstance, inferInstance, inferInstance⟩ end CategoryTheory.Abelian
.lake/packages/mathlib/Mathlib/CategoryTheory/Abelian/Opposite.lean
import Mathlib.CategoryTheory.Abelian.Basic import Mathlib.CategoryTheory.Preadditive.Opposite import Mathlib.CategoryTheory.Limits.Opposites /-! # The opposite of an abelian category is abelian. -/ noncomputable section namespace CategoryTheory open CategoryTheory.Limits variable (C : Type*) [Category C] [Abelian C] instance : Abelian Cᵒᵖ := { normalMonoOfMono f := ⟨normalMonoOfNormalEpiUnop _ (normalEpiOfEpi f.unop)⟩ normalEpiOfEpi f := ⟨normalEpiOfNormalMonoUnop _ (normalMonoOfMono f.unop)⟩ } section variable {C} variable {X Y : C} (f : X ⟶ Y) {A B : Cᵒᵖ} (g : A ⟶ B) -- TODO: Generalize (this will work whenever f has a cokernel) -- (The abelian case is probably sufficient for most applications.) /-- The kernel of `f.op` is the opposite of `cokernel f`. -/ @[simps] def kernelOpUnop : (kernel f.op).unop ≅ cokernel f where hom := (kernel.lift f.op (cokernel.π f).op <| by simp [← op_comp]).unop inv := cokernel.desc f (kernel.ι f.op).unop <| by rw [← f.unop_op, ← unop_comp, f.unop_op] simp hom_inv_id := by rw [← unop_id, ← (cokernel.desc f _ _).unop_op, ← unop_comp] congr 1 ext simp [← op_comp] inv_hom_id := by ext simp [← unop_comp] -- TODO: Generalize (this will work whenever f has a kernel) -- (The abelian case is probably sufficient for most applications.) /-- The cokernel of `f.op` is the opposite of `kernel f`. -/ @[simps] def cokernelOpUnop : (cokernel f.op).unop ≅ kernel f where hom := kernel.lift f (cokernel.π f.op).unop <| by rw [← f.unop_op, ← unop_comp, f.unop_op] simp inv := (cokernel.desc f.op (kernel.ι f).op <| by simp [← op_comp]).unop hom_inv_id := by rw [← unop_id, ← (kernel.lift f _ _).unop_op, ← unop_comp] congr 1 ext simp [← op_comp] inv_hom_id := by ext simp [← unop_comp] /-- The kernel of `g.unop` is the opposite of `cokernel g`. -/ @[simps!] def kernelUnopOp : Opposite.op (kernel g.unop) ≅ cokernel g := (cokernelOpUnop g.unop).op /-- The cokernel of `g.unop` is the opposite of `kernel g`. -/ @[simps!] def cokernelUnopOp : Opposite.op (cokernel g.unop) ≅ kernel g := (kernelOpUnop g.unop).op theorem cokernel.π_op : (cokernel.π f.op).unop = (cokernelOpUnop f).hom ≫ kernel.ι f ≫ eqToHom (Opposite.unop_op _).symm := by simp [cokernelOpUnop] theorem kernel.ι_op : (kernel.ι f.op).unop = eqToHom (Opposite.unop_op _) ≫ cokernel.π f ≫ (kernelOpUnop f).inv := by simp [kernelOpUnop] /-- The kernel of `f.op` is the opposite of `cokernel f`. -/ @[simps!] def kernelOpOp : kernel f.op ≅ Opposite.op (cokernel f) := (kernelOpUnop f).op.symm /-- The cokernel of `f.op` is the opposite of `kernel f`. -/ @[simps!] def cokernelOpOp : cokernel f.op ≅ Opposite.op (kernel f) := (cokernelOpUnop f).op.symm /-- The kernel of `g.unop` is the opposite of `cokernel g`. -/ @[simps!] def kernelUnopUnop : kernel g.unop ≅ (cokernel g).unop := (kernelUnopOp g).unop.symm theorem kernel.ι_unop : (kernel.ι g.unop).op = eqToHom (Opposite.op_unop _) ≫ cokernel.π g ≫ (kernelUnopOp g).inv := by simp theorem cokernel.π_unop : (cokernel.π g.unop).op = (cokernelUnopOp g).hom ≫ kernel.ι g ≫ eqToHom (Opposite.op_unop _).symm := by simp /-- The cokernel of `g.unop` is the opposite of `kernel g`. -/ @[simps!] def cokernelUnopUnop : cokernel g.unop ≅ (kernel g).unop := (cokernelUnopOp g).unop.symm /-- The opposite of the image of `g.unop` is the image of `g.` -/ def imageUnopOp : Opposite.op (image g.unop) ≅ image g := (Abelian.imageIsoImage _).op ≪≫ (cokernelOpOp _).symm ≪≫ cokernelIsoOfEq (cokernel.π_unop _) ≪≫ cokernelEpiComp _ _ ≪≫ cokernelCompIsIso _ _ ≪≫ Abelian.coimageIsoImage' _ /-- The opposite of the image of `f` is the image of `f.op`. -/ def imageOpOp : Opposite.op (image f) ≅ image f.op := imageUnopOp f.op /-- The image of `f.op` is the opposite of the image of `f`. -/ def imageOpUnop : (image f.op).unop ≅ image f := (imageUnopOp f.op).unop /-- The image of `g` is the opposite of the image of `g.unop.` -/ def imageUnopUnop : (image g).unop ≅ image g.unop := (imageUnopOp g).unop theorem image_ι_op_comp_imageUnopOp_hom : (image.ι g.unop).op ≫ (imageUnopOp g).hom = factorThruImage g := by simp only [imageUnopOp, Iso.trans, Iso.symm, Iso.op, cokernelOpOp_inv, cokernelEpiComp_hom, cokernelCompIsIso_hom, Abelian.coimageIsoImage'_hom, ← Category.assoc, ← op_comp] simp only [Category.assoc, Abelian.imageIsoImage_hom_comp_image_ι, kernel.lift_ι, Quiver.Hom.op_unop, cokernelIsoOfEq_hom_comp_desc_assoc, cokernel.π_desc_assoc, cokernel.π_desc] simp only [eqToHom_refl] rw [IsIso.inv_id, Category.id_comp] theorem imageUnopOp_hom_comp_image_ι : (imageUnopOp g).hom ≫ image.ι g = (factorThruImage g.unop).op := by simp only [← cancel_epi (image.ι g.unop).op, ← Category.assoc, image_ι_op_comp_imageUnopOp_hom, ← op_comp, image.fac, Quiver.Hom.op_unop] theorem factorThruImage_comp_imageUnopOp_inv : factorThruImage g ≫ (imageUnopOp g).inv = (image.ι g.unop).op := by rw [Iso.comp_inv_eq, image_ι_op_comp_imageUnopOp_hom] theorem imageUnopOp_inv_comp_op_factorThruImage : (imageUnopOp g).inv ≫ (factorThruImage g.unop).op = image.ι g := by rw [Iso.inv_comp_eq, imageUnopOp_hom_comp_image_ι] end end CategoryTheory end
.lake/packages/mathlib/Mathlib/CategoryTheory/Abelian/RightDerived.lean
import Mathlib.Algebra.Homology.Additive import Mathlib.CategoryTheory.Abelian.Injective.Resolution /-! # Right-derived functors We define the right-derived functors `F.rightDerived n : C ⥤ D` for any additive functor `F` out of a category with injective resolutions. We first define a functor `F.rightDerivedToHomotopyCategory : C ⥤ HomotopyCategory D (ComplexShape.up ℕ)` which is `injectiveResolutions C ⋙ F.mapHomotopyCategory _`. We show that if `X : C` and `I : InjectiveResolution X`, then `F.rightDerivedToHomotopyCategory.obj X` identifies to the image in the homotopy category of the functor `F` applied objectwise to `I.cocomplex` (this isomorphism is `I.isoRightDerivedToHomotopyCategoryObj F`). Then, the right-derived functors `F.rightDerived n : C ⥤ D` are obtained by composing `F.rightDerivedToHomotopyCategory` with the homology functors on the homotopy category. Similarly we define natural transformations between right-derived functors coming from natural transformations between the original additive functors, and show how to compute the components. ## Main results * `Functor.isZero_rightDerived_obj_injective_succ`: injective objects have no higher right derived functor. * `NatTrans.rightDerived`: the natural isomorphism between right derived functors induced by natural transformation. * `Functor.toRightDerivedZero`: the natural transformation `F ⟶ F.rightDerived 0`, which is an isomorphism when `F` is left exact (i.e. preserves finite limits), see also `Functor.rightDerivedZeroIsoSelf`. ## TODO * refactor `Functor.rightDerived` (and `Functor.leftDerived`) when the necessary material enters mathlib: derived categories, injective/projective derivability structures, existence of derived functors from derivability structures. Eventually, we shall get a right derived functor `F.rightDerivedFunctorPlus : DerivedCategory.Plus C ⥤ DerivedCategory.Plus D`, and `F.rightDerived` shall be redefined using `F.rightDerivedFunctorPlus`. -/ universe v u namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] {D : Type*} [Category D] [Abelian C] [HasInjectiveResolutions C] [Abelian D] /-- When `F : C ⥤ D` is an additive functor, this is the functor `C ⥤ HomotopyCategory D (ComplexShape.up ℕ)` which sends `X : C` to `F` applied to an injective resolution of `X`. -/ noncomputable def Functor.rightDerivedToHomotopyCategory (F : C ⥤ D) [F.Additive] : C ⥤ HomotopyCategory D (ComplexShape.up ℕ) := injectiveResolutions C ⋙ F.mapHomotopyCategory _ /-- If `I : InjectiveResolution Z` and `F : C ⥤ D` is an additive functor, this is an isomorphism between `F.rightDerivedToHomotopyCategory.obj X` and the complex obtained by applying `F` to `I.cocomplex`. -/ noncomputable def InjectiveResolution.isoRightDerivedToHomotopyCategoryObj {X : C} (I : InjectiveResolution X) (F : C ⥤ D) [F.Additive] : F.rightDerivedToHomotopyCategory.obj X ≅ (F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).obj I.cocomplex := (F.mapHomotopyCategory _).mapIso I.iso ≪≫ (F.mapHomotopyCategoryFactors _).app I.cocomplex @[reassoc] lemma InjectiveResolution.isoRightDerivedToHomotopyCategoryObj_hom_naturality {X Y : C} (f : X ⟶ Y) (I : InjectiveResolution X) (J : InjectiveResolution Y) (φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0) (F : C ⥤ D) [F.Additive] : F.rightDerivedToHomotopyCategory.map f ≫ (J.isoRightDerivedToHomotopyCategoryObj F).hom = (I.isoRightDerivedToHomotopyCategoryObj F).hom ≫ (F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).map φ := by dsimp [Functor.rightDerivedToHomotopyCategory, isoRightDerivedToHomotopyCategoryObj] rw [← Functor.map_comp_assoc, iso_hom_naturality f I J φ comm, Functor.map_comp, assoc, assoc] erw [(F.mapHomotopyCategoryFactors (ComplexShape.up ℕ)).hom.naturality] rfl @[reassoc] lemma InjectiveResolution.isoRightDerivedToHomotopyCategoryObj_inv_naturality {X Y : C} (f : X ⟶ Y) (I : InjectiveResolution X) (J : InjectiveResolution Y) (φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0) (F : C ⥤ D) [F.Additive] : (I.isoRightDerivedToHomotopyCategoryObj F).inv ≫ F.rightDerivedToHomotopyCategory.map f = (F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).map φ ≫ (J.isoRightDerivedToHomotopyCategoryObj F).inv := by rw [← cancel_epi (I.isoRightDerivedToHomotopyCategoryObj F).hom, Iso.hom_inv_id_assoc] dsimp rw [← isoRightDerivedToHomotopyCategoryObj_hom_naturality_assoc f I J φ comm F, Iso.hom_inv_id, comp_id] /-- The right derived functors of an additive functor. -/ noncomputable def Functor.rightDerived (F : C ⥤ D) [F.Additive] (n : ℕ) : C ⥤ D := F.rightDerivedToHomotopyCategory ⋙ HomotopyCategory.homologyFunctor D _ n /-- We can compute a right derived functor using a chosen injective resolution. -/ noncomputable def InjectiveResolution.isoRightDerivedObj {X : C} (I : InjectiveResolution X) (F : C ⥤ D) [F.Additive] (n : ℕ) : (F.rightDerived n).obj X ≅ (HomologicalComplex.homologyFunctor D _ n).obj ((F.mapHomologicalComplex _).obj I.cocomplex) := (HomotopyCategory.homologyFunctor D _ n).mapIso (I.isoRightDerivedToHomotopyCategoryObj F) ≪≫ (HomotopyCategory.homologyFunctorFactors D (ComplexShape.up ℕ) n).app _ @[reassoc] lemma InjectiveResolution.isoRightDerivedObj_hom_naturality {X Y : C} (f : X ⟶ Y) (I : InjectiveResolution X) (J : InjectiveResolution Y) (φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0) (F : C ⥤ D) [F.Additive] (n : ℕ) : (F.rightDerived n).map f ≫ (J.isoRightDerivedObj F n).hom = (I.isoRightDerivedObj F n).hom ≫ (F.mapHomologicalComplex _ ⋙ HomologicalComplex.homologyFunctor _ _ n).map φ := by dsimp [isoRightDerivedObj, Functor.rightDerived] rw [assoc, ← Functor.map_comp_assoc, InjectiveResolution.isoRightDerivedToHomotopyCategoryObj_hom_naturality f I J φ comm F, Functor.map_comp, assoc] erw [(HomotopyCategory.homologyFunctorFactors D (ComplexShape.up ℕ) n).hom.naturality] rfl @[reassoc] lemma InjectiveResolution.isoRightDerivedObj_inv_naturality {X Y : C} (f : X ⟶ Y) (I : InjectiveResolution X) (J : InjectiveResolution Y) (φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0) (F : C ⥤ D) [F.Additive] (n : ℕ) : (I.isoRightDerivedObj F n).inv ≫ (F.rightDerived n).map f = (F.mapHomologicalComplex _ ⋙ HomologicalComplex.homologyFunctor _ _ n).map φ ≫ (J.isoRightDerivedObj F n).inv := by rw [← cancel_mono (J.isoRightDerivedObj F n).hom, assoc, assoc, InjectiveResolution.isoRightDerivedObj_hom_naturality f I J φ comm F n, Iso.inv_hom_id_assoc, Iso.inv_hom_id, comp_id] /-- The higher derived functors vanish on injective objects. -/ lemma Functor.isZero_rightDerived_obj_injective_succ (F : C ⥤ D) [F.Additive] (n : ℕ) (X : C) [Injective X] : IsZero ((F.rightDerived (n + 1)).obj X) := by refine IsZero.of_iso ?_ ((InjectiveResolution.self X).isoRightDerivedObj F (n + 1)) erw [← HomologicalComplex.exactAt_iff_isZero_homology] exact ShortComplex.exact_of_isZero_X₂ _ (F.map_isZero (by apply isZero_zero)) /-- We can compute a right derived functor on a morphism using a descent of that morphism to a cochain map between chosen injective resolutions. -/ theorem Functor.rightDerived_map_eq (F : C ⥤ D) [F.Additive] (n : ℕ) {X Y : C} (f : X ⟶ Y) {P : InjectiveResolution X} {Q : InjectiveResolution Y} (g : P.cocomplex ⟶ Q.cocomplex) (w : P.ι ≫ g = (CochainComplex.single₀ C).map f ≫ Q.ι) : (F.rightDerived n).map f = (P.isoRightDerivedObj F n).hom ≫ (F.mapHomologicalComplex _ ⋙ HomologicalComplex.homologyFunctor _ _ n).map g ≫ (Q.isoRightDerivedObj F n).inv := by rw [← cancel_mono (Q.isoRightDerivedObj F n).hom, InjectiveResolution.isoRightDerivedObj_hom_naturality f P Q g _ F n, assoc, assoc, Iso.inv_hom_id, comp_id] rw [← HomologicalComplex.comp_f, w, HomologicalComplex.comp_f, CochainComplex.single₀_map_f_zero] /-- The natural transformation `F.rightDerivedToHomotopyCategory ⟶ G.rightDerivedToHomotopyCategory` induced by a natural transformation `F ⟶ G` between additive functors. -/ noncomputable def NatTrans.rightDerivedToHomotopyCategory {F G : C ⥤ D} [F.Additive] [G.Additive] (α : F ⟶ G) : F.rightDerivedToHomotopyCategory ⟶ G.rightDerivedToHomotopyCategory := Functor.whiskerLeft _ (NatTrans.mapHomotopyCategory α (ComplexShape.up ℕ)) lemma InjectiveResolution.rightDerivedToHomotopyCategory_app_eq {F G : C ⥤ D} [F.Additive] [G.Additive] (α : F ⟶ G) {X : C} (P : InjectiveResolution X) : (NatTrans.rightDerivedToHomotopyCategory α).app X = (P.isoRightDerivedToHomotopyCategoryObj F).hom ≫ (HomotopyCategory.quotient _ _).map ((NatTrans.mapHomologicalComplex α _).app P.cocomplex) ≫ (P.isoRightDerivedToHomotopyCategoryObj G).inv := by rw [← cancel_mono (P.isoRightDerivedToHomotopyCategoryObj G).hom, assoc, assoc, Iso.inv_hom_id, comp_id] dsimp [isoRightDerivedToHomotopyCategoryObj, Functor.mapHomotopyCategoryFactors, NatTrans.rightDerivedToHomotopyCategory] rw [assoc] erw [id_comp, comp_id] obtain ⟨β, hβ⟩ := (HomotopyCategory.quotient _ _).map_surjective (iso P).hom rw [← hβ] dsimp simp only [← Functor.map_comp, NatTrans.mapHomologicalComplex_naturality] rfl @[simp] lemma NatTrans.rightDerivedToHomotopyCategory_id (F : C ⥤ D) [F.Additive] : NatTrans.rightDerivedToHomotopyCategory (𝟙 F) = 𝟙 _ := rfl @[simp, reassoc] lemma NatTrans.rightDerivedToHomotopyCategory_comp {F G H : C ⥤ D} (α : F ⟶ G) (β : G ⟶ H) [F.Additive] [G.Additive] [H.Additive] : NatTrans.rightDerivedToHomotopyCategory (α ≫ β) = NatTrans.rightDerivedToHomotopyCategory α ≫ NatTrans.rightDerivedToHomotopyCategory β := rfl /-- The natural transformation between right-derived functors induced by a natural transformation. -/ noncomputable def NatTrans.rightDerived {F G : C ⥤ D} [F.Additive] [G.Additive] (α : F ⟶ G) (n : ℕ) : F.rightDerived n ⟶ G.rightDerived n := Functor.whiskerRight (NatTrans.rightDerivedToHomotopyCategory α) _ @[simp] theorem NatTrans.rightDerived_id (F : C ⥤ D) [F.Additive] (n : ℕ) : NatTrans.rightDerived (𝟙 F) n = 𝟙 (F.rightDerived n) := by dsimp only [rightDerived] simp only [rightDerivedToHomotopyCategory_id, Functor.whiskerRight_id'] rfl @[simp, reassoc] theorem NatTrans.rightDerived_comp {F G H : C ⥤ D} [F.Additive] [G.Additive] [H.Additive] (α : F ⟶ G) (β : G ⟶ H) (n : ℕ) : NatTrans.rightDerived (α ≫ β) n = NatTrans.rightDerived α n ≫ NatTrans.rightDerived β n := by simp [NatTrans.rightDerived] namespace InjectiveResolution /-- A component of the natural transformation between right-derived functors can be computed using a chosen injective resolution. -/ lemma rightDerived_app_eq {F G : C ⥤ D} [F.Additive] [G.Additive] (α : F ⟶ G) {X : C} (P : InjectiveResolution X) (n : ℕ) : (NatTrans.rightDerived α n).app X = (P.isoRightDerivedObj F n).hom ≫ (HomologicalComplex.homologyFunctor D (ComplexShape.up ℕ) n).map ((NatTrans.mapHomologicalComplex α _).app P.cocomplex) ≫ (P.isoRightDerivedObj G n).inv := by dsimp [NatTrans.rightDerived, isoRightDerivedObj] rw [InjectiveResolution.rightDerivedToHomotopyCategory_app_eq α P, Functor.map_comp, Functor.map_comp, assoc] erw [← (HomotopyCategory.homologyFunctorFactors D (ComplexShape.up ℕ) n).hom.naturality_assoc ((NatTrans.mapHomologicalComplex α (ComplexShape.up ℕ)).app P.cocomplex)] simp only [Functor.comp_map, Iso.hom_inv_id_app_assoc] /-- If `P : InjectiveResolution X` and `F` is an additive functor, this is the canonical morphism from `F.obj X` to the cycles in degree `0` of `(F.mapHomologicalComplex _).obj P.cocomplex`. -/ noncomputable def toRightDerivedZero' {X : C} (P : InjectiveResolution X) (F : C ⥤ D) [F.Additive] : F.obj X ⟶ ((F.mapHomologicalComplex _).obj P.cocomplex).cycles 0 := HomologicalComplex.liftCycles _ (F.map (P.ι.f 0)) 1 (by simp) (by dsimp rw [← F.map_comp, HomologicalComplex.Hom.comm, HomologicalComplex.single_obj_d, zero_comp, F.map_zero]) @[reassoc (attr := simp)] lemma toRightDerivedZero'_comp_iCycles {C} [Category C] [Abelian C] {X : C} (P : InjectiveResolution X) (F : C ⥤ D) [F.Additive] : P.toRightDerivedZero' F ≫ HomologicalComplex.iCycles _ _ = F.map (P.ι.f 0) := by simp [toRightDerivedZero'] @[reassoc] lemma toRightDerivedZero'_naturality {C} [Category C] [Abelian C] {X Y : C} (f : X ⟶ Y) (P : InjectiveResolution X) (Q : InjectiveResolution Y) (φ : P.cocomplex ⟶ Q.cocomplex) (comm : P.ι.f 0 ≫ φ.f 0 = f ≫ Q.ι.f 0) (F : C ⥤ D) [F.Additive] : F.map f ≫ Q.toRightDerivedZero' F = P.toRightDerivedZero' F ≫ HomologicalComplex.cyclesMap ((F.mapHomologicalComplex _).map φ) 0 := by simp only [← cancel_mono (HomologicalComplex.iCycles _ _), Functor.mapHomologicalComplex_obj_X, assoc, toRightDerivedZero'_comp_iCycles, CochainComplex.single₀_obj_zero, HomologicalComplex.cyclesMap_i, Functor.mapHomologicalComplex_map_f, toRightDerivedZero'_comp_iCycles_assoc, ← F.map_comp, comm] instance (F : C ⥤ D) [F.Additive] (X : C) [Injective X] : IsIso ((InjectiveResolution.self X).toRightDerivedZero' F) := by dsimp [InjectiveResolution.toRightDerivedZero'] rw [CochainComplex.isIso_liftCycles_iff] refine ⟨ShortComplex.Splitting.exact ?_, inferInstance⟩ exact { r := 𝟙 _ s := 0 s_g := (F.map_isZero (isZero_zero _)).eq_of_src _ _ } end InjectiveResolution /-- The natural transformation `F ⟶ F.rightDerived 0`. -/ noncomputable def Functor.toRightDerivedZero (F : C ⥤ D) [F.Additive] : F ⟶ F.rightDerived 0 where app X := (injectiveResolution X).toRightDerivedZero' F ≫ (CochainComplex.isoHomologyπ₀ _).hom ≫ (HomotopyCategory.homologyFunctorFactors D (ComplexShape.up ℕ) 0).inv.app _ naturality {X Y} f := by dsimp [rightDerived] rw [assoc, assoc, InjectiveResolution.toRightDerivedZero'_naturality_assoc f (injectiveResolution X) (injectiveResolution Y) (InjectiveResolution.desc f _ _) (by simp), ← HomologicalComplex.homologyπ_naturality_assoc] erw [← NatTrans.naturality] rfl lemma InjectiveResolution.toRightDerivedZero_eq {X : C} (I : InjectiveResolution X) (F : C ⥤ D) [F.Additive] : F.toRightDerivedZero.app X = I.toRightDerivedZero' F ≫ (CochainComplex.isoHomologyπ₀ _).hom ≫ (I.isoRightDerivedObj F 0).inv := by dsimp [Functor.toRightDerivedZero, isoRightDerivedObj] have h₁ := InjectiveResolution.toRightDerivedZero'_naturality (𝟙 X) (injectiveResolution X) I (desc (𝟙 X) _ _) (by simp) F simp only [Functor.map_id, id_comp] at h₁ have h₂ : (I.isoRightDerivedToHomotopyCategoryObj F).hom = (F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).map (desc (𝟙 X) _ _) := comp_id _ rw [← cancel_mono ((HomotopyCategory.homologyFunctor _ _ 0).map (I.isoRightDerivedToHomotopyCategoryObj F).hom), assoc, assoc, assoc, assoc, assoc, ← Functor.map_comp, Iso.inv_hom_id, Functor.map_id, comp_id, reassoc_of% h₁, h₂, ← HomologicalComplex.homologyπ_naturality_assoc] erw [← NatTrans.naturality] rfl instance (F : C ⥤ D) [F.Additive] (X : C) [Injective X] : IsIso (F.toRightDerivedZero.app X) := by rw [(InjectiveResolution.self X).toRightDerivedZero_eq F] infer_instance section variable (F : C ⥤ D) [F.Additive] [PreservesFiniteLimits F] instance {X : C} (P : InjectiveResolution X) : IsIso (P.toRightDerivedZero' F) := by dsimp [InjectiveResolution.toRightDerivedZero'] rw [CochainComplex.isIso_liftCycles_iff, ShortComplex.exact_and_mono_f_iff_f_is_kernel] exact ⟨KernelFork.mapIsLimit _ (P.isLimitKernelFork) F⟩ instance (X : C) : IsIso (F.toRightDerivedZero.app X) := by dsimp [Functor.toRightDerivedZero] infer_instance instance : IsIso F.toRightDerivedZero := NatIso.isIso_of_isIso_app _ namespace Functor /-- The canonical isomorphism `F.rightDerived 0 ≅ F` when `F` is left exact (i.e. preserves finite limits). -/ @[simps! inv] noncomputable def rightDerivedZeroIsoSelf : F.rightDerived 0 ≅ F := (asIso F.toRightDerivedZero).symm @[reassoc (attr := simp)] lemma rightDerivedZeroIsoSelf_hom_inv_id : F.rightDerivedZeroIsoSelf.hom ≫ F.toRightDerivedZero = 𝟙 _ := F.rightDerivedZeroIsoSelf.hom_inv_id @[reassoc (attr := simp)] lemma rightDerivedZeroIsoSelf_inv_hom_id : F.toRightDerivedZero ≫ F.rightDerivedZeroIsoSelf.hom = 𝟙 _ := F.rightDerivedZeroIsoSelf.inv_hom_id @[reassoc (attr := simp)] lemma rightDerivedZeroIsoSelf_hom_inv_id_app (X : C) : F.rightDerivedZeroIsoSelf.hom.app X ≫ F.toRightDerivedZero.app X = 𝟙 _ := F.rightDerivedZeroIsoSelf.hom_inv_id_app X @[reassoc (attr := simp)] lemma rightDerivedZeroIsoSelf_inv_hom_id_app (X : C) : F.toRightDerivedZero.app X ≫ F.rightDerivedZeroIsoSelf.hom.app X = 𝟙 _ := F.rightDerivedZeroIsoSelf.inv_hom_id_app X end Functor end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Abelian/Indization.lean
import Mathlib.CategoryTheory.Preadditive.Indization import Mathlib.CategoryTheory.Abelian.FunctorCategory import Mathlib.CategoryTheory.Limits.Preserves.Shapes.AbelianImages /-! # The category of ind-objects is abelian We show that if `C` is a small abelian category, then `Ind C` is an abelian category. In the file `Mathlib/CategoryTheory/Abelian/GrothendieckAxioms/Indization.lean`, we show that in this situation `Ind C` is in fact Grothendieck abelian. -/ universe v open CategoryTheory.Abelian namespace CategoryTheory variable {C : Type v} [SmallCategory C] [Abelian C] instance {X Y : Ind C} (f : X ⟶ Y) : IsIso (Abelian.coimageImageComparison f) := by obtain ⟨I, _, _, F, G, ϕ, ⟨i⟩⟩ := Ind.exists_nonempty_arrow_mk_iso_ind_lim (f := f) let i' := coimageImageComparisonFunctor.mapIso i dsimp only [coimageImageComparisonFunctor_obj, Arrow.mk_left, Arrow.mk_right, Arrow.mk_hom] at i' have := Iso.isIso_hom i' rw [Arrow.isIso_iff_isIso_of_isIso i'.hom, Arrow.isIso_iff_isIso_of_isIso (PreservesCoimageImageComparison.iso (Ind.lim I) ϕ).inv] infer_instance noncomputable instance : Abelian (Ind C) := .ofCoimageImageComparisonIsIso end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Abelian/Pseudoelements.lean
import Mathlib.CategoryTheory.Abelian.Exact import Mathlib.CategoryTheory.Comma.Over.Basic import Mathlib.Algebra.Category.ModuleCat.EpiMono /-! # Pseudoelements in abelian categories A *pseudoelement* of an object `X` in an abelian category `C` is an equivalence class of arrows ending in `X`, where two arrows are considered equivalent if we can find two epimorphisms with a common domain making a commutative square with the two arrows. While the construction shows that pseudoelements are actually subobjects of `X` rather than "elements", it is possible to chase these pseudoelements through commutative diagrams in an abelian category to prove exactness properties. This is done using some "diagram-chasing metatheorems" proved in this file. In many cases, a proof in the category of abelian groups can more or less directly be converted into a proof using pseudoelements. A classic application of pseudoelements are diagram lemmas like the four lemma or the snake lemma. Pseudoelements are in some ways weaker than actual elements in a concrete category. The most important limitation is that there is no extensionality principle: If `f g : X ⟶ Y`, then `∀ x ∈ X, f x = g x` does not necessarily imply that `f = g` (however, if `f = 0` or `g = 0`, it does). A corollary of this is that we cannot define arrows in abelian categories by dictating their action on pseudoelements. Thus, a usual style of proofs in abelian categories is this: First, we construct some morphism using universal properties, and then we use diagram chasing of pseudoelements to verify that is has some desirable property such as exactness. It should be noted that the Freyd-Mitchell embedding theorem (see `CategoryTheory.Abelian.FreydMitchell`) gives a vastly stronger notion of pseudoelement (in particular one that gives extensionality) and this file should be updated to go use that instead! ## Main results We define the type of pseudoelements of an object and, in particular, the zero pseudoelement. We prove that every morphism maps the zero pseudoelement to the zero pseudoelement (`apply_zero`) and that a zero morphism maps every pseudoelement to the zero pseudoelement (`zero_apply`). Here are the metatheorems we provide: * A morphism `f` is zero if and only if it is the zero function on pseudoelements. * A morphism `f` is an epimorphism if and only if it is surjective on pseudoelements. * A morphism `f` is a monomorphism if and only if it is injective on pseudoelements if and only if `∀ a, f a = 0 → f = 0`. * A sequence `f, g` of morphisms is exact if and only if `∀ a, g (f a) = 0` and `∀ b, g b = 0 → ∃ a, f a = b`. * If `f` is a morphism and `a, a'` are such that `f a = f a'`, then there is some pseudoelement `a''` such that `f a'' = 0` and for every `g` we have `g a' = 0 → g a = g a''`. We can think of `a''` as `a - a'`, but don't get too carried away by that: pseudoelements of an object do not form an abelian group. ## Notation We introduce coercions from an object of an abelian category to the set of its pseudoelements and from a morphism to the function it induces on pseudoelements. These coercions must be explicitly enabled via local instances: `attribute [local instance] objectToSort homToFun` ## Implementation notes It appears that sometimes the coercion from morphisms to functions does not work, i.e., writing `g a` raises a "function expected" error. This error can be fixed by writing `(g : X ⟶ Y) a`. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ open CategoryTheory open CategoryTheory.Limits open CategoryTheory.Abelian open CategoryTheory.Preadditive universe v u namespace CategoryTheory.Abelian variable {C : Type u} [Category.{v} C] attribute [local instance] Over.coeFromHom /-- This is just composition of morphisms in `C`. Another way to express this would be `(Over.map f).obj a`, but our definition has nicer definitional properties. -/ def app {P Q : C} (f : P ⟶ Q) (a : Over P) : Over Q := a.hom ≫ f @[simp] theorem app_hom {P Q : C} (f : P ⟶ Q) (a : Over P) : (app f a).hom = a.hom ≫ f := rfl /-- Two arrows `f : X ⟶ P` and `g : Y ⟶ P` are called pseudo-equal if there is some object `R` and epimorphisms `p : R ⟶ X` and `q : R ⟶ Y` such that `p ≫ f = q ≫ g`. -/ def PseudoEqual (P : C) (f g : Over P) : Prop := ∃ (R : C) (p : R ⟶ f.1) (q : R ⟶ g.1) (_ : Epi p) (_ : Epi q), p ≫ f.hom = q ≫ g.hom theorem pseudoEqual_refl {P : C} : Reflexive (PseudoEqual P) := fun f => ⟨f.1, 𝟙 f.1, 𝟙 f.1, inferInstance, inferInstance, by simp⟩ theorem pseudoEqual_symm {P : C} : Symmetric (PseudoEqual P) := fun _ _ ⟨R, p, q, ep, Eq, comm⟩ => ⟨R, q, p, Eq, ep, comm.symm⟩ variable [Abelian.{v} C] section /-- Pseudoequality is transitive: Just take the pullback. The pullback morphisms will be epimorphisms since in an abelian category, pullbacks of epimorphisms are epimorphisms. -/ theorem pseudoEqual_trans {P : C} : Transitive (PseudoEqual P) := by intro f g h ⟨R, p, q, ep, Eq, comm⟩ ⟨R', p', q', ep', eq', comm'⟩ refine ⟨pullback q p', pullback.fst _ _ ≫ p, pullback.snd _ _ ≫ q', epi_comp _ _, epi_comp _ _, ?_⟩ rw [Category.assoc, comm, ← Category.assoc, pullback.condition, Category.assoc, comm', Category.assoc] end /-- The arrows with codomain `P` equipped with the equivalence relation of being pseudo-equal. -/ def Pseudoelement.setoid (P : C) : Setoid (Over P) := ⟨_, ⟨pseudoEqual_refl, @pseudoEqual_symm _ _ _, @pseudoEqual_trans _ _ _ _⟩⟩ attribute [local instance] Pseudoelement.setoid /-- A `Pseudoelement` of `P` is just an equivalence class of arrows ending in `P` by being pseudo-equal. -/ def Pseudoelement (P : C) : Type max u v := Quotient (Pseudoelement.setoid P) namespace Pseudoelement /-- A coercion from an object of an abelian category to its pseudoelements. -/ def objectToSort : CoeSort C (Type max u v) := ⟨fun P => Pseudoelement P⟩ attribute [local instance] objectToSort scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.objectToSort /-- A coercion from an arrow with codomain `P` to its associated pseudoelement. -/ def overToSort {P : C} : Coe (Over P) (Pseudoelement P) := ⟨Quot.mk (PseudoEqual P)⟩ attribute [local instance] overToSort theorem over_coe_def {P Q : C} (a : Q ⟶ P) : (a : Pseudoelement P) = ⟦↑a⟧ := rfl /-- If two elements are pseudo-equal, then their composition with a morphism is, too. -/ theorem pseudoApply_aux {P Q : C} (f : P ⟶ Q) (a b : Over P) : a ≈ b → app f a ≈ app f b := fun ⟨R, p, q, ep, Eq, comm⟩ => ⟨R, p, q, ep, Eq, show p ≫ a.hom ≫ f = q ≫ b.hom ≫ f by rw [reassoc_of% comm]⟩ /-- A morphism `f` induces a function `pseudoApply f` on pseudoelements. -/ def pseudoApply {P Q : C} (f : P ⟶ Q) : P → Q := Quotient.map (fun g : Over P => app f g) (pseudoApply_aux f) /-- A coercion from morphisms to functions on pseudoelements. -/ def homToFun {P Q : C} : CoeFun (P ⟶ Q) fun _ => P → Q := ⟨pseudoApply⟩ attribute [local instance] homToFun scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.homToFun theorem pseudoApply_mk' {P Q : C} (f : P ⟶ Q) (a : Over P) : f ⟦a⟧ = ⟦↑(a.hom ≫ f)⟧ := rfl /-- Applying a pseudoelement to a composition of morphisms is the same as composing with each morphism. Sadly, this is not a definitional equality, but at least it is true. -/ theorem comp_apply {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) (a : P) : (f ≫ g) a = g (f a) := Quotient.inductionOn a fun x => Quotient.sound <| by simp only [app] rw [← Category.assoc, Over.coe_hom] /-- Composition of functions on pseudoelements is composition of morphisms. -/ theorem comp_comp {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) : g ∘ f = f ≫ g := funext fun _ => (comp_apply _ _ _).symm section Zero /-! In this section we prove that for every `P` there is an equivalence class that contains precisely all the zero morphisms ending in `P` and use this to define *the* zero pseudoelement. -/ section attribute [local instance] HasBinaryBiproducts.of_hasBinaryProducts /-- The arrows pseudo-equal to a zero morphism are precisely the zero morphisms. -/ theorem pseudoZero_aux {P : C} (Q : C) (f : Over P) : f ≈ (0 : Q ⟶ P) ↔ f.hom = 0 := ⟨fun ⟨R, p, q, _, _, comm⟩ => zero_of_epi_comp p (by simp [comm]), fun hf => ⟨biprod f.1 Q, biprod.fst, biprod.snd, inferInstance, inferInstance, by rw [hf, Over.coe_hom, HasZeroMorphisms.comp_zero, HasZeroMorphisms.comp_zero]⟩⟩ end theorem zero_eq_zero' {P Q R : C} : (⟦((0 : Q ⟶ P) : Over P)⟧ : Pseudoelement P) = ⟦((0 : R ⟶ P) : Over P)⟧ := Quotient.sound <| (pseudoZero_aux R _).2 rfl /-- The zero pseudoelement is the class of a zero morphism. -/ def pseudoZero {P : C} : P := ⟦(0 : P ⟶ P)⟧ instance hasZero {P : C} : Zero P := ⟨pseudoZero⟩ instance {P : C} : Inhabited P := ⟨0⟩ theorem pseudoZero_def {P : C} : (0 : Pseudoelement P) = ⟦↑(0 : P ⟶ P)⟧ := rfl @[simp] theorem zero_eq_zero {P Q : C} : ⟦((0 : Q ⟶ P) : Over P)⟧ = (0 : Pseudoelement P) := zero_eq_zero' /-- The pseudoelement induced by an arrow is zero precisely when that arrow is zero. -/ theorem pseudoZero_iff {P : C} (a : Over P) : a = (0 : P) ↔ a.hom = 0 := by rw [← pseudoZero_aux P a] exact Quotient.eq' end Zero open Pseudoelement /-- Morphisms map the zero pseudoelement to the zero pseudoelement. -/ @[simp] theorem apply_zero {P Q : C} (f : P ⟶ Q) : f 0 = 0 := by rw [pseudoZero_def, pseudoApply_mk'] simp /-- The zero morphism maps every pseudoelement to 0. -/ @[simp] theorem zero_apply {P : C} (Q : C) (a : P) : (0 : P ⟶ Q) a = 0 := Quotient.inductionOn a fun a' => by rw [pseudoZero_def, pseudoApply_mk'] simp /-- An extensionality lemma for being the zero arrow. -/ theorem zero_morphism_ext {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0) → f = 0 := fun h => by rw [← Category.id_comp f] exact (pseudoZero_iff (𝟙 P ≫ f : Over Q)).1 (h (𝟙 P)) theorem zero_morphism_ext' {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0) → 0 = f := Eq.symm ∘ zero_morphism_ext f theorem eq_zero_iff {P Q : C} (f : P ⟶ Q) : f = 0 ↔ ∀ a, f a = 0 := ⟨fun h a => by simp [h], zero_morphism_ext _⟩ /-- A monomorphism is injective on pseudoelements. -/ theorem pseudo_injective_of_mono {P Q : C} (f : P ⟶ Q) [Mono f] : Function.Injective f := by intro abar abar' refine Quotient.inductionOn₂ abar abar' fun a a' ha => ?_ apply Quotient.sound have : (⟦(a.hom ≫ f : Over Q)⟧ : Quotient (setoid Q)) = ⟦↑(a'.hom ≫ f)⟧ := by convert ha have ⟨R, p, q, ep, Eq, comm⟩ := Quotient.exact this exact ⟨R, p, q, ep, Eq, (cancel_mono f).1 <| by simp only [Category.assoc] exact comm⟩ /-- A morphism that is injective on pseudoelements only maps the zero element to zero. -/ theorem zero_of_map_zero {P Q : C} (f : P ⟶ Q) : Function.Injective f → ∀ a, f a = 0 → a = 0 := fun h a ha => by rw [← apply_zero f] at ha exact h ha /-- A morphism that only maps the zero pseudoelement to zero is a monomorphism. -/ theorem mono_of_zero_of_map_zero {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0 → a = 0) → Mono f := fun h => (mono_iff_cancel_zero _).2 fun _ g hg => (pseudoZero_iff (g : Over P)).1 <| h _ <| show f g = 0 from (pseudoZero_iff (g ≫ f : Over Q)).2 hg section /-- An epimorphism is surjective on pseudoelements. -/ theorem pseudo_surjective_of_epi {P Q : C} (f : P ⟶ Q) [Epi f] : Function.Surjective f := fun qbar => Quotient.inductionOn qbar fun q => ⟨(pullback.fst f q.hom : Over P), Quotient.sound <| ⟨pullback f q.hom, 𝟙 (pullback f q.hom), pullback.snd _ _, inferInstance, inferInstance, by rw [Category.id_comp, ← pullback.condition, app_hom, Over.coe_hom]⟩⟩ end /-- A morphism that is surjective on pseudoelements is an epimorphism. -/ theorem epi_of_pseudo_surjective {P Q : C} (f : P ⟶ Q) : Function.Surjective f → Epi f := by intro h have ⟨pbar, hpbar⟩ := h (𝟙 Q) have ⟨p, hp⟩ := Quotient.exists_rep pbar have : (⟦(p.hom ≫ f : Over Q)⟧ : Quotient (setoid Q)) = ⟦↑(𝟙 Q)⟧ := by rw [← hp] at hpbar exact hpbar have ⟨R, x, y, _, ey, comm⟩ := Quotient.exact this apply @epi_of_epi_fac _ _ _ _ _ (x ≫ p.hom) f y ey dsimp at comm rw [Category.assoc, comm] apply Category.comp_id section /-- Two morphisms in an exact sequence are exact on pseudoelements. -/ theorem pseudo_exact_of_exact {S : ShortComplex C} (hS : S.Exact) : ∀ b, S.g b = 0 → ∃ a, S.f a = b := fun b' => Quotient.inductionOn b' fun b hb => by have hb' : b.hom ≫ S.g = 0 := (pseudoZero_iff _).1 hb -- By exactness, `b` factors through `im f = ker g` via some `c`. obtain ⟨c, hc⟩ := KernelFork.IsLimit.lift' hS.isLimitImage _ hb' -- We compute the pullback of the map into the image and `c`. -- The pseudoelement induced by the first pullback map will be our preimage. use pullback.fst (Abelian.factorThruImage S.f) c -- It remains to show that the image of this element under `f` is pseudo-equal to `b`. apply Quotient.sound refine ⟨pullback (Abelian.factorThruImage S.f) c, 𝟙 _, pullback.snd _ _, inferInstance, inferInstance, ?_⟩ -- Now we can verify that the diagram commutes. calc 𝟙 (pullback (Abelian.factorThruImage S.f) c) ≫ pullback.fst _ _ ≫ S.f = pullback.fst _ _ ≫ S.f := Category.id_comp _ _ = pullback.fst _ _ ≫ Abelian.factorThruImage S.f ≫ kernel.ι (cokernel.π S.f) := by rw [Abelian.image.fac] _ = (pullback.snd _ _ ≫ c) ≫ kernel.ι (cokernel.π S.f) := by rw [← Category.assoc, pullback.condition] _ = pullback.snd _ _ ≫ b.hom := by rw [Category.assoc] congr end theorem apply_eq_zero_of_comp_eq_zero {P Q R : C} (f : Q ⟶ R) (a : P ⟶ Q) : a ≫ f = 0 → f a = 0 := fun h => by simp [over_coe_def, pseudoApply_mk', h] section /-- If two morphisms are exact on pseudoelements, they are exact. -/ theorem exact_of_pseudo_exact (S : ShortComplex C) (hS : ∀ b, S.g b = 0 → ∃ a, S.f a = b) : S.Exact := (S.exact_iff_kernel_ι_comp_cokernel_π_zero).2 (by -- If we apply `g` to the pseudoelement induced by its kernel, we get 0 (of course!). have : S.g (kernel.ι S.g) = 0 := apply_eq_zero_of_comp_eq_zero _ _ (kernel.condition _) -- By pseudo-exactness, we get a preimage. obtain ⟨a', ha⟩ := hS _ this obtain ⟨a, ha'⟩ := Quotient.exists_rep a' rw [← ha'] at ha obtain ⟨Z, r, q, _, eq, comm⟩ := Quotient.exact ha -- Consider the pullback of `kernel.ι (cokernel.π f)` and `kernel.ι g`. -- The commutative diagram given by the pseudo-equality `f a = b` induces -- a cone over this pullback, so we get a factorization `z`. obtain ⟨z, _, hz₂⟩ := @pullback.lift' _ _ _ _ _ _ (kernel.ι (cokernel.π S.f)) (kernel.ι S.g) _ (r ≫ a.hom ≫ Abelian.factorThruImage S.f) q (by simp only [Category.assoc, Abelian.image.fac] exact comm) -- Let's give a name to the second pullback morphism. let j : pullback (kernel.ι (cokernel.π S.f)) (kernel.ι S.g) ⟶ kernel S.g := pullback.snd _ _ -- Since `q` is an epimorphism, in particular this means that `j` is an epimorphism. haveI pe : Epi j := epi_of_epi_fac hz₂ -- But it is also a monomorphism, because `kernel.ι (cokernel.π f)` is: A kernel is -- always a monomorphism and the pullback of a monomorphism is a monomorphism. -- But mono + epi = iso, so `j` is an isomorphism. haveI : IsIso j := isIso_of_mono_of_epi _ -- But then `kernel.ι g` can be expressed using all of the maps of the pullback square, and we -- are done. rw [(Iso.eq_inv_comp (asIso j)).2 pullback.condition.symm] simp only [Category.assoc, kernel.condition, HasZeroMorphisms.comp_zero]) end /-- If two pseudoelements `x` and `y` have the same image under some morphism `f`, then we can form their "difference" `z`. This pseudoelement has the properties that `f z = 0` and for all morphisms `g`, if `g y = 0` then `g z = g x`. -/ theorem sub_of_eq_image {P Q : C} (f : P ⟶ Q) (x y : P) : f x = f y → ∃ z, f z = 0 ∧ ∀ (R : C) (g : P ⟶ R), (g : P ⟶ R) y = 0 → g z = g x := Quotient.inductionOn₂ x y fun a a' h => match Quotient.exact h with | ⟨R, p, q, ep, _, comm⟩ => let a'' : R ⟶ P := (p ≫ a.hom : R ⟶ P) - (q ≫ a'.hom : R ⟶ P) ⟨a'', ⟨show ⟦(a'' ≫ f : Over Q)⟧ = ⟦↑(0 : Q ⟶ Q)⟧ by dsimp at comm simp [a'', sub_eq_zero.2 comm], fun Z g hh => by obtain ⟨X, p', q', ep', _, comm'⟩ := Quotient.exact hh have : a'.hom ≫ g = 0 := by apply (epi_iff_cancel_zero _).1 ep' _ (a'.hom ≫ g) simpa using comm' apply Quotient.sound -- Can we prevent quotient.sound from giving us this weird `coe_b` thingy? change app g (a'' : Over P) ≈ app g a exact ⟨R, 𝟙 R, p, inferInstance, ep, by simp [a'', sub_eq_add_neg, this]⟩⟩⟩ variable [Limits.HasPullbacks C] /-- If `f : P ⟶ R` and `g : Q ⟶ R` are morphisms and `p : P` and `q : Q` are pseudoelements such that `f p = g q`, then there is some `s : pullback f g` such that `fst s = p` and `snd s = q`. Remark: Borceux claims that `s` is unique, but this is false. See `Counterexamples/Pseudoelement.lean` for details. -/ theorem pseudo_pullback {P Q R : C} {f : P ⟶ R} {g : Q ⟶ R} {p : P} {q : Q} : f p = g q → ∃ s, pullback.fst f g s = p ∧ pullback.snd f g s = q := Quotient.inductionOn₂ p q fun x y h => by obtain ⟨Z, a, b, ea, eb, comm⟩ := Quotient.exact h obtain ⟨l, hl₁, hl₂⟩ := @pullback.lift' _ _ _ _ _ _ f g _ (a ≫ x.hom) (b ≫ y.hom) (by simp only [Category.assoc] exact comm) exact ⟨l, ⟨Quotient.sound ⟨Z, 𝟙 Z, a, inferInstance, ea, by rwa [Category.id_comp]⟩, Quotient.sound ⟨Z, 𝟙 Z, b, inferInstance, eb, by rwa [Category.id_comp]⟩⟩⟩ section Module /-- In the category `Module R`, if `x` and `y` are pseudoequal, then the range of the associated morphisms is the same. -/ theorem ModuleCat.eq_range_of_pseudoequal {R : Type*} [Ring R] {G : ModuleCat R} {x y : Over G} (h : PseudoEqual G x y) : LinearMap.range x.hom.hom = LinearMap.range y.hom.hom := by obtain ⟨P, p, q, hp, hq, H⟩ := h refine Submodule.ext fun a => ⟨fun ha => ?_, fun ha => ?_⟩ · obtain ⟨a', ha'⟩ := ha obtain ⟨a'', ha''⟩ := (ModuleCat.epi_iff_surjective p).1 hp a' refine ⟨q a'', ?_⟩ dsimp at ha' ⊢ rw [← LinearMap.comp_apply, ← ModuleCat.hom_comp, ← H, ModuleCat.hom_comp, LinearMap.comp_apply, ha'', ha'] · obtain ⟨a', ha'⟩ := ha obtain ⟨a'', ha''⟩ := (ModuleCat.epi_iff_surjective q).1 hq a' refine ⟨p a'', ?_⟩ dsimp at ha' ⊢ rw [← LinearMap.comp_apply, ← ModuleCat.hom_comp, H, ModuleCat.hom_comp, LinearMap.comp_apply, ha'', ha'] end Module end Pseudoelement end CategoryTheory.Abelian
.lake/packages/mathlib/Mathlib/CategoryTheory/Abelian/Basic.lean
import Mathlib.CategoryTheory.Limits.Constructions.Pullbacks import Mathlib.CategoryTheory.Preadditive.Biproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers import Mathlib.CategoryTheory.Abelian.NonPreadditive /-! # Abelian categories This file contains the definition and basic properties of abelian categories. There are many definitions of abelian category. Our definition is as follows: A category is called abelian if it is preadditive, has a finite products, kernels and cokernels, and if every monomorphism and epimorphism is normal. It should be noted that if we also assume coproducts, then preadditivity is actually a consequence of the other properties, as we show in `NonPreadditiveAbelian.lean`. However, this fact is of little practical relevance, since essentially all interesting abelian categories come with a preadditive structure. In this way, by requiring preadditivity, we allow the user to pass in the "native" preadditive structure for the specific category they are working with. ## Main definitions * `Abelian` is the type class indicating that a category is abelian. It extends `Preadditive`. * `Abelian.image f` is `kernel (cokernel.π f)`, and * `Abelian.coimage f` is `cokernel (kernel.ι f)`. ## Main results * In an abelian category, mono + epi = iso. * If `f : X ⟶ Y`, then the map `factorThruImage f : X ⟶ image f` is an epimorphism, and the map `factorThruCoimage f : coimage f ⟶ Y` is a monomorphism. * Factoring through the image and coimage is a strong epi-mono factorisation. This means that * every abelian category has images. We provide the isomorphism `imageIsoImage : abelian.image f ≅ limits.image f`. * the canonical morphism `coimageImageComparison : coimage f ⟶ image f` is an isomorphism. * We provide the alternate characterisation of an abelian category as a category with (co)kernels and finite products, and in which the canonical coimage-image comparison morphism is always an isomorphism. * Every epimorphism is a cokernel of its kernel. Every monomorphism is a kernel of its cokernel. * The pullback of an epimorphism is an epimorphism. The pushout of a monomorphism is a monomorphism. (This is not to be confused with the fact that the pullback of a monomorphism is a monomorphism, which is true in any category). ## Implementation notes The typeclass `Abelian` does not extend `NonPreadditiveAbelian`, to avoid having to deal with comparing the two `HasZeroMorphisms` instances (one from `Preadditive` in `Abelian`, and the other a field of `NonPreadditiveAbelian`). As a consequence, at the beginning of this file we trivially build a `NonPreadditiveAbelian` instance from an `Abelian` instance, and use this to restate a number of theorems, in each case just reusing the proof from `NonPreadditiveAbelian.lean`. We don't show this yet, but abelian categories are finitely complete and finitely cocomplete. However, the limits we can construct at this level of generality will most likely be less nice than the ones that can be created in specific applications. For this reason, we adopt the following convention: * If the statement of a theorem involves limits, the existence of these limits should be made an explicit typeclass parameter. * If a limit only appears in a proof, but not in the statement of a theorem, the limit should not be a typeclass parameter, but instead be created using `Abelian.hasPullbacks` or a similar definition. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] * [P. Aluffi, *Algebra: Chapter 0*][aluffi2016] -/ noncomputable section open CategoryTheory open CategoryTheory.Preadditive open CategoryTheory.Limits universe v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] variable (C) /-- A (preadditive) category `C` is called abelian if it has all finite products, all kernels and cokernels, and if every monomorphism is the kernel of some morphism and every epimorphism is the cokernel of some morphism. (This definition implies the existence of zero objects: finite products give a terminal object, and in a preadditive category any terminal object is a zero object.) -/ class Abelian extends Preadditive C, IsNormalMonoCategory C, IsNormalEpiCategory C where [has_finite_products : HasFiniteProducts C] [has_kernels : HasKernels C] [has_cokernels : HasCokernels C] -- These instances should have a lower priority, or typeclass search times out. attribute [instance 100] Abelian.has_finite_products attribute [instance 100] Abelian.has_kernels Abelian.has_cokernels end CategoryTheory open CategoryTheory /-! We begin by providing an alternative constructor: a preadditive category with kernels, cokernels, and finite products, in which the coimage-image comparison morphism is always an isomorphism, is an abelian category. -/ namespace CategoryTheory.Abelian variable {C : Type u} [Category.{v} C] [Preadditive C] variable [Limits.HasKernels C] [Limits.HasCokernels C] namespace OfCoimageImageComparisonIsIso /-- The factorisation of a morphism through its abelian image. -/ @[simps] def imageMonoFactorisation {X Y : C} (f : X ⟶ Y) : MonoFactorisation f where I := Abelian.image f m := kernel.ι _ m_mono := inferInstance e := kernel.lift _ f (cokernel.condition _) fac := kernel.lift_ι _ _ _ theorem imageMonoFactorisation_e' {X Y : C} (f : X ⟶ Y) : (imageMonoFactorisation f).e = cokernel.π _ ≫ Abelian.coimageImageComparison f := by dsimp ext simp only [Abelian.coimageImageComparison, Category.assoc, cokernel.π_desc_assoc] /-- If the coimage-image comparison morphism for a morphism `f` is an isomorphism, we obtain an image factorisation of `f`. -/ def imageFactorisation {X Y : C} (f : X ⟶ Y) [IsIso (Abelian.coimageImageComparison f)] : ImageFactorisation f where F := imageMonoFactorisation f isImage := { lift := fun F => inv (Abelian.coimageImageComparison f) ≫ cokernel.desc _ F.e F.kernel_ι_comp lift_fac := fun F => by rw [imageMonoFactorisation_m] simp only [Category.assoc] rw [IsIso.inv_comp_eq] ext simp } instance [HasZeroObject C] {X Y : C} (f : X ⟶ Y) [Mono f] [IsIso (Abelian.coimageImageComparison f)] : IsIso (imageMonoFactorisation f).e := by rw [imageMonoFactorisation_e'] exact IsIso.comp_isIso instance [HasZeroObject C] {X Y : C} (f : X ⟶ Y) [Epi f] : IsIso (imageMonoFactorisation f).m := by dsimp infer_instance variable [∀ {X Y : C} (f : X ⟶ Y), IsIso (Abelian.coimageImageComparison f)] /-- A category in which coimage-image comparisons are all isomorphisms has images. -/ theorem hasImages : HasImages C := { has_image := fun {_} {_} f => { exists_image := ⟨imageFactorisation f⟩ } } variable [Limits.HasFiniteProducts C] attribute [local instance] Limits.HasFiniteBiproducts.of_hasFiniteProducts /-- A category with finite products in which coimage-image comparisons are all isomorphisms is a normal mono category. -/ lemma isNormalMonoCategory : IsNormalMonoCategory C where normalMonoOfMono f m := ⟨{ Z := _ g := cokernel.π f w := by simp isLimit := by haveI : Limits.HasImages C := hasImages haveI : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels haveI : HasZeroObject C := Limits.hasZeroObject_of_hasFiniteBiproducts _ have aux : ∀ (s : KernelFork (cokernel.π f)), (limit.lift (parallelPair (cokernel.π f) 0) s ≫ inv (imageMonoFactorisation f).e) ≫ Fork.ι (KernelFork.ofι f (by simp)) = Fork.ι s := ?_ · refine isLimitAux _ (fun A => limit.lift _ _ ≫ inv (imageMonoFactorisation f).e) aux ?_ intro A g hg rw [KernelFork.ι_ofι] at hg rw [← cancel_mono f, hg, ← aux, KernelFork.ι_ofι] · intro A simp only [KernelFork.ι_ofι, Category.assoc] convert limit.lift_π A WalkingParallelPair.zero using 2 rw [IsIso.inv_comp_eq, eq_comm] exact (imageMonoFactorisation f).fac }⟩ /-- A category with finite products in which coimage-image comparisons are all isomorphisms is a normal epi category. -/ lemma isNormalEpiCategory : IsNormalEpiCategory C where normalEpiOfEpi f m := ⟨{ W := kernel f g := kernel.ι _ w := kernel.condition _ isColimit := by haveI : Limits.HasImages C := hasImages haveI : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels haveI : HasZeroObject C := Limits.hasZeroObject_of_hasFiniteBiproducts _ have aux : ∀ (s : CokernelCofork (kernel.ι f)), Cofork.π (CokernelCofork.ofπ f (by simp)) ≫ inv (imageMonoFactorisation f).m ≫ inv (Abelian.coimageImageComparison f) ≫ colimit.desc (parallelPair (kernel.ι f) 0) s = Cofork.π s := ?_ · refine isColimitAux _ (fun A => inv (imageMonoFactorisation f).m ≫ inv (Abelian.coimageImageComparison f) ≫ colimit.desc _ _) aux ?_ intro A g hg rw [CokernelCofork.π_ofπ] at hg rw [← cancel_epi f, hg, ← aux, CokernelCofork.π_ofπ] · intro A simp only [CokernelCofork.π_ofπ, ← Category.assoc] convert colimit.ι_desc A WalkingParallelPair.one using 2 rw [IsIso.comp_inv_eq, IsIso.comp_inv_eq, eq_comm, ← imageMonoFactorisation_e'] exact (imageMonoFactorisation f).fac }⟩ end OfCoimageImageComparisonIsIso variable [∀ {X Y : C} (f : X ⟶ Y), IsIso (Abelian.coimageImageComparison f)] [Limits.HasFiniteProducts C] attribute [local instance] OfCoimageImageComparisonIsIso.isNormalMonoCategory attribute [local instance] OfCoimageImageComparisonIsIso.isNormalEpiCategory /-- A preadditive category with kernels, cokernels, and finite products, in which the coimage-image comparison morphism is always an isomorphism, is an abelian category. -/ @[stacks 0109 "The Stacks project uses this characterisation at the definition of an abelian category."] def ofCoimageImageComparisonIsIso : Abelian C where end CategoryTheory.Abelian namespace CategoryTheory.Abelian variable {C : Type u} [Category.{v} C] [Abelian C] -- Porting note: this should be an instance, -- but triggers https://github.com/leanprover/lean4/issues/2055 -- (this is still the case despite that issue being closed now). -- We set it as a local instance instead. -- instance (priority := 100) -- Turning it into a global instance breaks `Mathlib/Algebra/Category/ModuleCat/Sheaf/Free.lean`. /-- An abelian category has finite biproducts. -/ theorem hasFiniteBiproducts : HasFiniteBiproducts C := Limits.HasFiniteBiproducts.of_hasFiniteProducts attribute [local instance] hasFiniteBiproducts instance (priority := 100) hasBinaryBiproducts : HasBinaryBiproducts C := Limits.hasBinaryBiproducts_of_finite_biproducts _ instance (priority := 100) hasZeroObject : HasZeroObject C := hasZeroObject_of_hasInitial_object section ToNonPreadditiveAbelian /-- Every abelian category is, in particular, `NonPreadditiveAbelian`. -/ def nonPreadditiveAbelian : NonPreadditiveAbelian C := { ‹Abelian C› with } end ToNonPreadditiveAbelian section /-! We now promote some instances that were constructed using `non_preadditive_abelian`. -/ attribute [local instance] nonPreadditiveAbelian variable {P Q : C} (f : P ⟶ Q) /-- The map `p : P ⟶ image f` is an epimorphism -/ instance : Epi (Abelian.factorThruImage f) := by infer_instance instance isIso_factorThruImage [Mono f] : IsIso (Abelian.factorThruImage f) := by infer_instance /-- The canonical morphism `i : coimage f ⟶ Q` is a monomorphism -/ instance : Mono (Abelian.factorThruCoimage f) := by infer_instance instance isIso_factorThruCoimage [Epi f] : IsIso (Abelian.factorThruCoimage f) := by infer_instance end section Factor attribute [local instance] nonPreadditiveAbelian variable {P Q : C} (f : P ⟶ Q) section theorem mono_of_kernel_ι_eq_zero (h : kernel.ι f = 0) : Mono f := mono_of_kernel_zero h theorem epi_of_cokernel_π_eq_zero (h : cokernel.π f = 0) : Epi f := epi_of_cokernel_zero h end section variable {f} theorem image_ι_comp_eq_zero {R : C} {g : Q ⟶ R} (h : f ≫ g = 0) : Abelian.image.ι f ≫ g = 0 := zero_of_epi_comp (Abelian.factorThruImage f) <| by simp [h] theorem comp_coimage_π_eq_zero {R : C} {g : Q ⟶ R} (h : f ≫ g = 0) : f ≫ Abelian.coimage.π g = 0 := zero_of_comp_mono (Abelian.factorThruCoimage g) <| by simp [h] end /-- Factoring through the image is a strong epi-mono factorisation. -/ @[simps] def imageStrongEpiMonoFactorisation : StrongEpiMonoFactorisation f where I := Abelian.image f m := image.ι f m_mono := by infer_instance e := Abelian.factorThruImage f e_strong_epi := strongEpi_of_epi _ /-- Factoring through the coimage is a strong epi-mono factorisation. -/ @[simps] def coimageStrongEpiMonoFactorisation : StrongEpiMonoFactorisation f where I := Abelian.coimage f m := Abelian.factorThruCoimage f m_mono := by infer_instance e := coimage.π f e_strong_epi := strongEpi_of_epi _ end Factor section HasStrongEpiMonoFactorisations /-- An abelian category has strong epi-mono factorisations. -/ instance (priority := 100) : HasStrongEpiMonoFactorisations C := HasStrongEpiMonoFactorisations.mk fun f => imageStrongEpiMonoFactorisation f -- In particular, this means that it has well-behaved images. example : HasImages C := by infer_instance example : HasImageMaps C := by infer_instance end HasStrongEpiMonoFactorisations section Images variable {X Y : C} (f : X ⟶ Y) /-- The coimage-image comparison morphism is always an isomorphism in an abelian category. See `CategoryTheory.Abelian.ofCoimageImageComparisonIsIso` for the converse. -/ instance : IsIso (coimageImageComparison f) := by convert Iso.isIso_hom (IsImage.isoExt (coimageStrongEpiMonoFactorisation f).toMonoIsImage (imageStrongEpiMonoFactorisation f).toMonoIsImage) ext change _ = _ ≫ (imageStrongEpiMonoFactorisation f).m simp [-imageStrongEpiMonoFactorisation_m] /-- There is a canonical isomorphism between the abelian coimage and the abelian image of a morphism. -/ abbrev coimageIsoImage : Abelian.coimage f ≅ Abelian.image f := asIso (coimageImageComparison f) /-- There is a canonical isomorphism between the abelian coimage and the categorical image of a morphism. -/ abbrev coimageIsoImage' : Abelian.coimage f ≅ image f := IsImage.isoExt (coimageStrongEpiMonoFactorisation f).toMonoIsImage (Image.isImage f) theorem coimageIsoImage'_hom : (coimageIsoImage' f).hom = cokernel.desc _ (factorThruImage f) (by simp [← cancel_mono (Limits.image.ι f)]) := by ext simp only [← cancel_mono (Limits.image.ι f), IsImage.isoExt_hom, cokernel.π_desc, Category.assoc, IsImage.lift_ι, coimageStrongEpiMonoFactorisation_m, Limits.image.fac] theorem factorThruImage_comp_coimageIsoImage'_inv : factorThruImage f ≫ (coimageIsoImage' f).inv = cokernel.π _ := by simp only [IsImage.isoExt_inv, image.isImage_lift, image.fac_lift, coimageStrongEpiMonoFactorisation_e] variable {Z : C} (g : Y ⟶ Z) @[simp] lemma image.ι_comp_eq_zero : image.ι f ≫ g = 0 ↔ f ≫ g = 0 := by simp [← cancel_epi (Abelian.factorThruImage _)] @[simp] lemma coimage.comp_π_eq_zero : f ≫ coimage.π g = 0 ↔ f ≫ g = 0 := by simp [← cancel_mono (Abelian.factorThruCoimage _)] /-- `Abelian.image` as a functor from the arrow category. -/ @[simps] def im : Arrow C ⥤ C where obj f := Abelian.image f.hom map {f g} u := kernel.lift _ (Abelian.image.ι f.hom ≫ u.right) <| by simp [← Arrow.w_assoc u] @[deprecated (since := "2025-10-31")] noncomputable alias imageFunctor := im /-- `Abelian.coimage` as a functor from the arrow category. -/ @[simps] def coim : Arrow C ⥤ C where obj f := Abelian.coimage f.hom map {f g} u := cokernel.desc _ (u.left ≫ Abelian.coimage.π g.hom) <| by simp [← Category.assoc, coimage.comp_π_eq_zero]; simp @[deprecated (since := "2025-10-31")] noncomputable alias coimageFunctor := coim /-- The image and coimage of an arrow are naturally isomorphic. -/ @[simps!] def coimIsoIm : coim (C := C) ≅ im := NatIso.ofComponents fun _ ↦ Abelian.coimageIsoImage _ @[deprecated (since := "2025-10-31")] noncomputable alias coimageFunctorIsoImageFunctor := coimIsoIm /-- There is a canonical isomorphism between the abelian image and the categorical image of a morphism. -/ abbrev imageIsoImage : Abelian.image f ≅ image f := IsImage.isoExt (imageStrongEpiMonoFactorisation f).toMonoIsImage (Image.isImage f) theorem imageIsoImage_hom_comp_image_ι : (imageIsoImage f).hom ≫ Limits.image.ι _ = kernel.ι _ := by simp only [IsImage.isoExt_hom, IsImage.lift_ι, imageStrongEpiMonoFactorisation_m] theorem imageIsoImage_inv : (imageIsoImage f).inv = kernel.lift _ (Limits.image.ι f) (by simp [← cancel_epi (factorThruImage f)]) := by ext rw [IsImage.isoExt_inv, image.isImage_lift, Limits.image.fac_lift, imageStrongEpiMonoFactorisation_e, Category.assoc, kernel.lift_ι, equalizer_as_kernel, kernel.lift_ι, Limits.image.fac] end Images section CokernelOfKernel variable {X Y : C} {f : X ⟶ Y} attribute [local instance] nonPreadditiveAbelian /-- In an abelian category, an epi is the cokernel of its kernel. More precisely: If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel of `fork.ι s`. -/ def epiIsCokernelOfKernel [Epi f] (s : Fork f 0) (h : IsLimit s) : IsColimit (CokernelCofork.ofπ f (KernelFork.condition s)) := NonPreadditiveAbelian.epiIsCokernelOfKernel s h /-- In an abelian category, a mono is the kernel of its cokernel. More precisely: If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel of `cofork.π s`. -/ def monoIsKernelOfCokernel [Mono f] (s : Cofork f 0) (h : IsColimit s) : IsLimit (KernelFork.ofι f (CokernelCofork.condition s)) := NonPreadditiveAbelian.monoIsKernelOfCokernel s h variable (f) /-- In an abelian category, any morphism that turns to zero when precomposed with the kernel of an epimorphism factors through that epimorphism. -/ def epiDesc [Epi f] {T : C} (g : X ⟶ T) (hg : kernel.ι f ≫ g = 0) : Y ⟶ T := (epiIsCokernelOfKernel _ (limit.isLimit _)).desc (CokernelCofork.ofπ _ hg) @[reassoc (attr := simp)] theorem comp_epiDesc [Epi f] {T : C} (g : X ⟶ T) (hg : kernel.ι f ≫ g = 0) : f ≫ epiDesc f g hg = g := (epiIsCokernelOfKernel _ (limit.isLimit _)).fac (CokernelCofork.ofπ _ hg) WalkingParallelPair.one /-- In an abelian category, any morphism that turns to zero when postcomposed with the cokernel of a monomorphism factors through that monomorphism. -/ def monoLift [Mono f] {T : C} (g : T ⟶ Y) (hg : g ≫ cokernel.π f = 0) : T ⟶ X := (monoIsKernelOfCokernel _ (colimit.isColimit _)).lift (KernelFork.ofι _ hg) @[reassoc (attr := simp)] theorem monoLift_comp [Mono f] {T : C} (g : T ⟶ Y) (hg : g ≫ cokernel.π f = 0) : monoLift f g hg ≫ f = g := (monoIsKernelOfCokernel _ (colimit.isColimit _)).fac (KernelFork.ofι _ hg) WalkingParallelPair.zero section variable {D : Type*} [Category D] [HasZeroMorphisms D] /-- If `F : D ⥤ C` is a functor to an abelian category, `i : X ⟶ Y` is a morphism admitting a cokernel such that `F` preserves this cokernel and `F.map i` is a mono, then `F.map X` identifies to the kernel of `F.map (cokernel.π i)`. -/ noncomputable def isLimitMapConeOfKernelForkOfι {X Y : D} (i : X ⟶ Y) [HasCokernel i] (F : D ⥤ C) [F.PreservesZeroMorphisms] [Mono (F.map i)] [PreservesColimit (parallelPair i 0) F] : IsLimit (F.mapCone (KernelFork.ofι i (cokernel.condition i))) := by let e : parallelPair (cokernel.π (F.map i)) 0 ≅ parallelPair (cokernel.π i) 0 ⋙ F := parallelPair.ext (Iso.refl _) (asIso (cokernelComparison i F)) (by simp) (by simp) refine IsLimit.postcomposeInvEquiv e _ ?_ let hi := Abelian.monoIsKernelOfCokernel _ (cokernelIsCokernel (F.map i)) refine IsLimit.ofIsoLimit hi (Fork.ext (Iso.refl _) ?_) change 𝟙 _ ≫ F.map i ≫ 𝟙 _ = F.map i rw [Category.comp_id, Category.id_comp] /-- If `F : D ⥤ C` is a functor to an abelian category, `p : X ⟶ Y` is a morphism admitting a kernel such that `F` preserves this kernel and `F.map p` is an epi, then `F.map Y` identifies to the cokernel of `F.map (kernel.ι p)`. -/ noncomputable def isColimitMapCoconeOfCokernelCoforkOfπ {X Y : D} (p : X ⟶ Y) [HasKernel p] (F : D ⥤ C) [F.PreservesZeroMorphisms] [Epi (F.map p)] [PreservesLimit (parallelPair p 0) F] : IsColimit (F.mapCocone (CokernelCofork.ofπ p (kernel.condition p))) := by let e : parallelPair (kernel.ι p) 0 ⋙ F ≅ parallelPair (kernel.ι (F.map p)) 0 := parallelPair.ext (asIso (kernelComparison p F)) (Iso.refl _) (by simp) (by simp) refine IsColimit.precomposeInvEquiv e _ ?_ let hp := Abelian.epiIsCokernelOfKernel _ (kernelIsKernel (F.map p)) refine IsColimit.ofIsoColimit hp (Cofork.ext (Iso.refl _) ?_) change F.map p ≫ 𝟙 _ = 𝟙 _ ≫ F.map p rw [Category.comp_id, Category.id_comp] end end CokernelOfKernel section instance (priority := 100) hasEqualizers : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels /-- Any abelian category has pullbacks -/ instance (priority := 100) hasPullbacks : HasPullbacks C := hasPullbacks_of_hasBinaryProducts_of_hasEqualizers C end section instance (priority := 100) hasCoequalizers : HasCoequalizers C := Preadditive.hasCoequalizers_of_hasCokernels /-- Any abelian category has pushouts -/ instance (priority := 100) hasPushouts : HasPushouts C := hasPushouts_of_hasBinaryCoproducts_of_hasCoequalizers C instance (priority := 100) hasFiniteLimits : HasFiniteLimits C := Limits.hasFiniteLimits_of_hasEqualizers_and_finite_products instance (priority := 100) hasFiniteColimits : HasFiniteColimits C := Limits.hasFiniteColimits_of_hasCoequalizers_and_finite_coproducts end namespace PullbackToBiproductIsKernel variable [Limits.HasPullbacks C] {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) /-! This section contains a slightly technical result about pullbacks and biproducts. We will need it in the proof that the pullback of an epimorphism is an epimorphism. -/ /-- The canonical map `pullback f g ⟶ X ⊞ Y` -/ abbrev pullbackToBiproduct : pullback f g ⟶ X ⊞ Y := biprod.lift (pullback.fst f g) (pullback.snd f g) /-- The canonical map `pullback f g ⟶ X ⊞ Y` induces a kernel cone on the map `biproduct X Y ⟶ Z` induced by `f` and `g`. A slightly more intuitive way to think of this may be that it induces an equalizer fork on the maps induced by `(f, 0)` and `(0, g)`. -/ abbrev pullbackToBiproductFork : KernelFork (biprod.desc f (-g)) := KernelFork.ofι (pullbackToBiproduct f g) <| by rw [biprod.lift_desc, comp_neg, pullback.condition, add_neg_cancel] /-- The canonical map `pullback f g ⟶ X ⊞ Y` is a kernel of the map induced by `(f, -g)`. -/ def isLimitPullbackToBiproduct : IsLimit (pullbackToBiproductFork f g) := Fork.IsLimit.mk _ (fun s => pullback.lift (Fork.ι s ≫ biprod.fst) (Fork.ι s ≫ biprod.snd) <| sub_eq_zero.1 <| by rw [Category.assoc, Category.assoc, ← comp_sub, sub_eq_add_neg, ← comp_neg, ← biprod.desc_eq, KernelFork.condition s]) (fun s => by apply biprod.hom_ext <;> rw [Fork.ι_ofι, Category.assoc] · rw [biprod.lift_fst, pullback.lift_fst] · rw [biprod.lift_snd, pullback.lift_snd]) fun s m h => by apply pullback.hom_ext <;> simp [← h] end PullbackToBiproductIsKernel namespace BiproductToPushoutIsCokernel variable [Limits.HasPushouts C] {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) /-- The canonical map `Y ⊞ Z ⟶ pushout f g` -/ abbrev biproductToPushout : Y ⊞ Z ⟶ pushout f g := biprod.desc (pushout.inl _ _) (pushout.inr _ _) /-- The canonical map `Y ⊞ Z ⟶ pushout f g` induces a cokernel cofork on the map `X ⟶ Y ⊞ Z` induced by `f` and `-g`. -/ abbrev biproductToPushoutCofork : CokernelCofork (biprod.lift f (-g)) := CokernelCofork.ofπ (biproductToPushout f g) <| by rw [biprod.lift_desc, neg_comp, pushout.condition, add_neg_cancel] /-- The cofork induced by the canonical map `Y ⊞ Z ⟶ pushout f g` is in fact a colimit cokernel cofork. -/ def isColimitBiproductToPushout : IsColimit (biproductToPushoutCofork f g) := Cofork.IsColimit.mk _ (fun s => pushout.desc (biprod.inl ≫ Cofork.π s) (biprod.inr ≫ Cofork.π s) <| sub_eq_zero.1 <| by rw [← Category.assoc, ← Category.assoc, ← sub_comp, sub_eq_add_neg, ← neg_comp, ← biprod.lift_eq, Cofork.condition s, zero_comp]) (fun s => by apply biprod.hom_ext' <;> simp) fun s m h => by apply pushout.hom_ext <;> simp [← h] end BiproductToPushoutIsCokernel section EpiPullback variable [Limits.HasPullbacks C] {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) /-- In an abelian category, the pullback of an epimorphism is an epimorphism. Proof from [aluffi2016, IX.2.3], cf. [borceux-vol2, 1.7.6] -/ instance epi_pullback_of_epi_f [Epi f] : Epi (pullback.snd f g) := -- It will suffice to consider some morphism e : Y ⟶ R such that -- pullback.snd f g ≫ e = 0 and show that e = 0. epi_of_cancel_zero _ fun {R} e h => by -- Consider the morphism u := (0, e) : X ⊞ Y⟶ R. let u := biprod.desc (0 : X ⟶ R) e -- The composite pullback f g ⟶ X ⊞ Y ⟶ R is zero by assumption. have hu : PullbackToBiproductIsKernel.pullbackToBiproduct f g ≫ u = 0 := by simpa [u] -- pullbackToBiproduct f g is a kernel of (f, -g), so (f, -g) is a -- cokernel of pullbackToBiproduct f g have := epiIsCokernelOfKernel _ (PullbackToBiproductIsKernel.isLimitPullbackToBiproduct f g) -- We use this fact to obtain a factorization of u through (f, -g) via some d : Z ⟶ R. obtain ⟨d, hd⟩ := CokernelCofork.IsColimit.desc' this u hu dsimp at d; dsimp [u] at hd -- But then f ≫ d = 0: have : f ≫ d = 0 := calc f ≫ d = (biprod.inl ≫ biprod.desc f (-g)) ≫ d := by rw [biprod.inl_desc] _ = biprod.inl ≫ u := by rw [Category.assoc, hd] _ = 0 := biprod.inl_desc _ _ -- But f is an epimorphism, so d = 0... have : d = 0 := (cancel_epi f).1 (by simpa) -- ...or, in other words, e = 0. calc e = biprod.inr ≫ biprod.desc (0 : X ⟶ R) e := by rw [biprod.inr_desc] _ = biprod.inr ≫ biprod.desc f (-g) ≫ d := by rw [← hd] _ = biprod.inr ≫ biprod.desc f (-g) ≫ 0 := by rw [this] _ = (biprod.inr ≫ biprod.desc f (-g)) ≫ 0 := by rw [← Category.assoc] _ = 0 := HasZeroMorphisms.comp_zero _ _ /-- In an abelian category, the pullback of an epimorphism is an epimorphism. -/ instance epi_pullback_of_epi_g [Epi g] : Epi (pullback.fst f g) := -- It will suffice to consider some morphism e : X ⟶ R such that -- pullback.fst f g ≫ e = 0 and show that e = 0. epi_of_cancel_zero _ fun {R} e h => by -- Consider the morphism u := (e, 0) : X ⊞ Y ⟶ R. let u := biprod.desc e (0 : Y ⟶ R) -- The composite pullback f g ⟶ X ⊞ Y ⟶ R is zero by assumption. have hu : PullbackToBiproductIsKernel.pullbackToBiproduct f g ≫ u = 0 := by simpa [u] -- pullbackToBiproduct f g is a kernel of (f, -g), so (f, -g) is a -- cokernel of pullbackToBiproduct f g have := epiIsCokernelOfKernel _ (PullbackToBiproductIsKernel.isLimitPullbackToBiproduct f g) -- We use this fact to obtain a factorization of u through (f, -g) via some d : Z ⟶ R. obtain ⟨d, hd⟩ := CokernelCofork.IsColimit.desc' this u hu dsimp at d; dsimp [u] at hd -- But then (-g) ≫ d = 0: have : (-g) ≫ d = 0 := calc (-g) ≫ d = (biprod.inr ≫ biprod.desc f (-g)) ≫ d := by rw [biprod.inr_desc] _ = biprod.inr ≫ u := by rw [Category.assoc, hd] _ = 0 := biprod.inr_desc _ _ -- But g is an epimorphism, thus so is -g, so d = 0... have : d = 0 := (cancel_epi (-g)).1 (by simpa) -- ...or, in other words, e = 0. calc e = biprod.inl ≫ biprod.desc e (0 : Y ⟶ R) := by rw [biprod.inl_desc] _ = biprod.inl ≫ biprod.desc f (-g) ≫ d := by rw [← hd] _ = biprod.inl ≫ biprod.desc f (-g) ≫ 0 := by rw [this] _ = (biprod.inl ≫ biprod.desc f (-g)) ≫ 0 := by rw [← Category.assoc] _ = 0 := HasZeroMorphisms.comp_zero _ _ theorem epi_snd_of_isLimit [Epi f] {s : PullbackCone f g} (hs : IsLimit s) : Epi s.snd := by haveI : Epi (NatTrans.app (limit.cone (cospan f g)).π WalkingCospan.right) := Abelian.epi_pullback_of_epi_f f g apply epi_of_epi_fac (IsLimit.conePointUniqueUpToIso_hom_comp (limit.isLimit _) hs _) theorem epi_fst_of_isLimit [Epi g] {s : PullbackCone f g} (hs : IsLimit s) : Epi s.fst := by haveI : Epi (NatTrans.app (limit.cone (cospan f g)).π WalkingCospan.left) := Abelian.epi_pullback_of_epi_g f g apply epi_of_epi_fac (IsLimit.conePointUniqueUpToIso_hom_comp (limit.isLimit _) hs _) /-- Suppose `f` and `g` are two morphisms with a common codomain and suppose we have written `g` as an epimorphism followed by a monomorphism. If `f` factors through the mono part of this factorization, then any pullback of `g` along `f` is an epimorphism. -/ theorem epi_fst_of_factor_thru_epi_mono_factorization (g₁ : Y ⟶ W) [Epi g₁] (g₂ : W ⟶ Z) [Mono g₂] (hg : g₁ ≫ g₂ = g) (f' : X ⟶ W) (hf : f' ≫ g₂ = f) (t : PullbackCone f g) (ht : IsLimit t) : Epi t.fst := by apply epi_fst_of_isLimit _ _ (PullbackCone.isLimitOfFactors f g g₂ f' g₁ hf hg t ht) end EpiPullback section MonoPushout variable [Limits.HasPushouts C] {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) instance mono_pushout_of_mono_f [Mono f] : Mono (pushout.inr _ _ : Z ⟶ pushout f g) := mono_of_cancel_zero _ fun {R} e h => by let u := biprod.lift (0 : R ⟶ Y) e have hu : u ≫ BiproductToPushoutIsCokernel.biproductToPushout f g = 0 := by simpa [u] have := monoIsKernelOfCokernel _ (BiproductToPushoutIsCokernel.isColimitBiproductToPushout f g) obtain ⟨d, hd⟩ := KernelFork.IsLimit.lift' this u hu dsimp at d dsimp [u] at hd have : d ≫ f = 0 := calc d ≫ f = d ≫ biprod.lift f (-g) ≫ biprod.fst := by rw [biprod.lift_fst] _ = u ≫ biprod.fst := by rw [← Category.assoc, hd] _ = 0 := biprod.lift_fst _ _ have : d = 0 := (cancel_mono f).1 (by simpa) calc e = biprod.lift (0 : R ⟶ Y) e ≫ biprod.snd := by rw [biprod.lift_snd] _ = (d ≫ biprod.lift f (-g)) ≫ biprod.snd := by rw [← hd] _ = (0 ≫ biprod.lift f (-g)) ≫ biprod.snd := by rw [this] _ = 0 ≫ biprod.lift f (-g) ≫ biprod.snd := by rw [Category.assoc] _ = 0 := zero_comp instance mono_pushout_of_mono_g [Mono g] : Mono (pushout.inl f g) := mono_of_cancel_zero _ fun {R} e h => by let u := biprod.lift e (0 : R ⟶ Z) have hu : u ≫ BiproductToPushoutIsCokernel.biproductToPushout f g = 0 := by simpa [u] have := monoIsKernelOfCokernel _ (BiproductToPushoutIsCokernel.isColimitBiproductToPushout f g) obtain ⟨d, hd⟩ := KernelFork.IsLimit.lift' this u hu dsimp at d dsimp [u] at hd have : d ≫ (-g) = 0 := calc d ≫ (-g) = d ≫ biprod.lift f (-g) ≫ biprod.snd := by rw [biprod.lift_snd] _ = biprod.lift e (0 : R ⟶ Z) ≫ biprod.snd := by rw [← Category.assoc, hd] _ = 0 := biprod.lift_snd _ _ have : d = 0 := (cancel_mono (-g)).1 (by simpa) calc e = biprod.lift e (0 : R ⟶ Z) ≫ biprod.fst := by rw [biprod.lift_fst] _ = (d ≫ biprod.lift f (-g)) ≫ biprod.fst := by rw [← hd] _ = (0 ≫ biprod.lift f (-g)) ≫ biprod.fst := by rw [this] _ = 0 ≫ biprod.lift f (-g) ≫ biprod.fst := by rw [Category.assoc] _ = 0 := zero_comp theorem mono_inr_of_isColimit [Mono f] {s : PushoutCocone f g} (hs : IsColimit s) : Mono s.inr := by haveI : Mono (NatTrans.app (colimit.cocone (span f g)).ι WalkingCospan.right) := Abelian.mono_pushout_of_mono_f f g apply mono_of_mono_fac (IsColimit.comp_coconePointUniqueUpToIso_hom hs (colimit.isColimit _) _) theorem mono_inl_of_isColimit [Mono g] {s : PushoutCocone f g} (hs : IsColimit s) : Mono s.inl := by haveI : Mono (NatTrans.app (colimit.cocone (span f g)).ι WalkingCospan.left) := Abelian.mono_pushout_of_mono_g f g apply mono_of_mono_fac (IsColimit.comp_coconePointUniqueUpToIso_hom hs (colimit.isColimit _) _) /-- Suppose `f` and `g` are two morphisms with a common domain and suppose we have written `g` as an epimorphism followed by a monomorphism. If `f` factors through the epi part of this factorization, then any pushout of `g` along `f` is a monomorphism. -/ theorem mono_inl_of_factor_thru_epi_mono_factorization (f : X ⟶ Y) (g : X ⟶ Z) (g₁ : X ⟶ W) [Epi g₁] (g₂ : W ⟶ Z) [Mono g₂] (hg : g₁ ≫ g₂ = g) (f' : W ⟶ Y) (hf : g₁ ≫ f' = f) (t : PushoutCocone f g) (ht : IsColimit t) : Mono t.inl := by apply mono_inl_of_isColimit _ _ (PushoutCocone.isColimitOfFactors _ _ _ _ _ hf hg t ht) end MonoPushout end CategoryTheory.Abelian namespace CategoryTheory.NonPreadditiveAbelian variable (C : Type u) [Category.{v} C] [NonPreadditiveAbelian C] /-- Every NonPreadditiveAbelian category can be promoted to an abelian category. -/ def abelian : Abelian C where toPreadditive := NonPreadditiveAbelian.preadditive normalMonoOfMono := fun f _ ↦ ⟨normalMonoOfMono f⟩ normalEpiOfEpi := fun f _ ↦ ⟨normalEpiOfEpi f⟩ end CategoryTheory.NonPreadditiveAbelian