import OAI.ArithmeticGeometry.Models.Algebra import Mathlib.Algebra.Category.Ring.FilteredColimits import Mathlib.AlgebraicGeometry.Limits import Mathlib.CategoryTheory.Limits.Types.Filtered import Mathlib.CategoryTheory.Limits.Preserves.Filtered /-! # Coefficient System -/ namespace OAI.ArithmeticGeometry.Models.CoefficientSystem.Constructions.Foundations /-! The filtered system of finite coefficient rings used in Foundations. -/ open _root_.CategoryTheory _root_.CategoryTheory.Limits _root_.AlgebraicGeometry universe u variable (R K : Type u) [CommRing R] [CommRing K] [Algebra R K] /-- The subalgebra generated by a finite set of coefficients. -/ noncomputable abbrev coefficientRing (s : Finset K) : Subalgebra R K := Algebra.adjoin R (s : Set K) /-- Inclusions of finite coefficient sets give inclusions of coefficient rings. -/ noncomputable def coefficientDiagram : Finset K ⥤ CommRingCat.{u} where obj s := CommRingCat.of (coefficientRing R K s) map h := CommRingCat.ofHom (Subalgebra.inclusion (Algebra.adjoin_mono (Finset.coe_subset.mpr (leOfHom h)))).toRingHom map_id _ := by ext x; rfl map_comp _ _ := by ext x; rfl /-- All finite coefficient rings map into the ambient ring. -/ noncomputable def coefficientCocone : Cocone (coefficientDiagram R K) where pt := CommRingCat.of K ι := { app := fun s ↦ CommRingCat.ofHom (coefficientRing R K s).val.toRingHom naturality := by intros; ext x; rfl } /-- Every coefficient occurs at a finite stage, and equality is witnessed at a common stage. -/ noncomputable def coefficientCoconeIsColimit : IsColimit (coefficientCocone R K) := by classical let : ReflectsColimitsOfShape (Finset K) (forget CommRingCat.{u}) := reflectsColimitsOfShape_of_reflectsIsomorphisms apply isColimitOfReflects (forget CommRingCat.{u}) apply Types.FilteredColimit.isColimitOf · intro x exact ⟨{x}, ⟨x, Algebra.subset_adjoin (Finset.mem_singleton_self x)⟩, rfl⟩ · intro s t x y h refine ⟨s ∪ t, homOfLE Finset.subset_union_left, homOfLE Finset.subset_union_right, ?_⟩ exact Subtype.ext h theorem coefficientRing_finiteType (s : Finset K) : Algebra.FiniteType R (coefficientRing R K s) := Algebra.FiniteType.adjoin_of_finite s.finite_toSet /-- Spectra form the corresponding cofiltered system. -/ noncomputable def coefficientSchemeDiagram : (Finset K)ᵒᵖ ⥤ Scheme.{u} := (coefficientDiagram R K).op ⋙ Scheme.Spec noncomputable def coefficientSchemeCone : Cone (coefficientSchemeDiagram R K) := Scheme.Spec.mapCone (coefficientCocone R K).op /-- The ambient affine scheme is the limit of its finite coefficient models. -/ noncomputable def coefficientSchemeConeIsLimit : IsLimit (coefficientSchemeCone R K) := isLimitOfPreserves Scheme.Spec (coefficientCoconeIsColimit R K).op /-- The affine base associated with a finite coefficient set. -/ noncomputable abbrev coefficientBase (s : Finset K) : Scheme.{u} := Spec (CommRingCat.of (coefficientRing R K s)) noncomputable abbrev genericBaseMap (s : Finset K) : Spec (CommRingCat.of K) ⟶ coefficientBase R K s := Spec.map ((coefficientCocone R K).ι.app s) noncomputable abbrev coefficientBaseMap {s t : Finset K} (h : s ⊆ t) : coefficientBase R K t ⟶ coefficientBase R K s := Spec.map ((coefficientDiagram R K).map (homOfLE h)) @[reassoc (attr := simp)] theorem genericBaseMap_comp {s t : Finset K} (h : s ⊆ t) : genericBaseMap R K t ≫ coefficientBaseMap R K h = genericBaseMap R K s := by dsimp [genericBaseMap, coefficientBaseMap, coefficientDiagram, coefficientCocone] rw [← Spec.map_comp] congr 1 @[reassoc (attr := simp)] theorem coefficientBaseMap_comp {s t v : Finset K} (hst : s ⊆ t) (htv : t ⊆ v) : coefficientBaseMap R K htv ≫ coefficientBaseMap R K hst = coefficientBaseMap R K (hst.trans htv) := by dsimp [coefficientBaseMap] erw [← Spec.map_comp, ← Functor.map_comp] rfl end OAI.ArithmeticGeometry.Models.CoefficientSystem.Constructions.Foundations