import OAI.NumberTheory.PiExponent.Ampleness.AmpleAllPowersGeneration import OAI.NumberTheory.PiExponent.Approximation.SectionOpens import OAI.NumberTheory.PiExponent.Cohomology.FiniteCoverCohomology namespace OAI namespace PiExponent.GeneratorsSectionCover noncomputable section open AlgebraicGeometry CategoryTheory CategoryTheory.Limits TopologicalSpace Opposite open PiExponentSeshadri.Geometry PiExponentSeshadri.Frames PiExponentSeshadri.SectionOpens variable {X : Scheme.{0}} private lemma epi_iso_comp {C : Type*} [Category C] {A B D E : C} (i : A ≅ B) (f : B ⟶ D) (e : D ≅ E) [Epi f] : Epi (i.hom ≫ f ≫ e.hom) := inferInstance private abbrev schemeFree (X : Scheme.{0}) (ι : Type) : X.Modules := SheafOfModules.free ι private abbrev schemeInclusion {X : Scheme.{0}} {ι : Type} (i : ι) : O X ⟶ schemeFree X ι := SheafOfModules.ιFree i def freeProjection {ι : Type} [DecidableEq ι] (i : ι) : schemeFree X ι ⟶ O X := Sigma.desc (C := X.Modules) (f := fun _ : ι => O X) (fun j => if j = i then 𝟙 _ else 0) @[simp] theorem free_inclusion_projection {ι : Type} [DecidableEq ι] (i j : ι) : schemeInclusion j ≫ freeProjection (X := X) i = if j = i then 𝟙 _ else 0 := by exact Sigma.ι_comp_desc (C := X.Modules) (f := fun _ : ι => O X) _ _ theorem free_sum_projection_inclusion {ι : Type} [Fintype ι] [DecidableEq ι] : (∑ i : ι, freeProjection (X := X) i ≫ schemeInclusion i) = 𝟙 (schemeFree X ι) := by apply (SheafOfModules.isColimitFreeCofan ι).hom_ext intro j change schemeInclusion j.as ≫ _ = schemeInclusion j.as ≫ _ simp only [Preadditive.comp_sum, ← Category.assoc, free_inclusion_projection] simp only [ite_comp, Category.id_comp, zero_comp, Fintype.sum_ite_eq, Category.comp_id] lemma hom_sum_app {M N : X.Modules} {ι : Type} (S : Finset ι) (f : ι → (M ⟶ N)) (V : X.Opens) (z : Γ(M,V)) : (∑ i ∈ S, f i).app V z = ∑ i ∈ S, (f i).app V z := by classical induction S using Finset.induction_on with | empty => rfl | @insert a S ha ih => simp only [Finset.sum_insert ha, Scheme.Modules.Hom.add_app] change (f a).app V z + (∑ i ∈ S, f i).app V z = _ rw [ih] theorem unit_epimorphism_cover {ι : Type} [Finite ι] (f : schemeFree X ι ⟶ O X) [Epi f] : (⨆ i : ι, isoOpen (schemeInclusion i ≫ f)) = ⊤ := by classical let : Fintype ι := Fintype.ofFinite ι apply top_unique intro x _ let F : X.Modules ⥤ _ := SheafOfModules.toSheaf X.ringCatSheaf have : F.PreservesEpimorphisms := inferInstanceAs (SheafOfModules.toSheaf X.ringCatSheaf).PreservesEpimorphisms have hFf : Epi (F.map f) := F.map_epi f have hloc : TopCat.Presheaf.IsLocallySurjective (F.map f).hom := (TopCat.Sheaf.isLocallySurjective_iff_epi _).mpr hFf obtain ⟨V, hV, ⟨z, hz⟩, hxV⟩ := (TopCat.Presheaf.isLocallySurjective_iff _).mp hloc ⊤ (1 : Γ(X,⊤)) x trivial change Scheme.Modules.Hom.app f V z = X.presheaf.map (homOfLE hV).op (1 : Γ(X,⊤)) at hz rw [map_one] at hz have he : (∑ i : ι, freeProjection (X := X) i ≫ (schemeInclusion i ≫ f)) = f := by simp only [← Category.assoc] rw [← Preadditive.sum_comp, free_sum_projection_inclusion, Category.id_comp] have hsum : (∑ i : ι, Scheme.Modules.Hom.app (schemeInclusion i ≫ f) V (Scheme.Modules.Hom.app (freeProjection (X := X) i) V z)) = (1 : Γ(X,V)) := by exact (hom_sum_app Finset.univ (fun i => freeProjection (X := X) i ≫ (schemeInclusion i ≫ f)) V z).symm.trans ((congrArg (fun q : (schemeFree X ι : X.Modules) ⟶ O X => Scheme.Modules.Hom.app q V z) he).trans hz) have hsum' : (∑ i : ι, X.presheaf.germ V x hxV (Scheme.Modules.Hom.app (schemeInclusion i ≫ f) V (Scheme.Modules.Hom.app (freeProjection (X := X) i) V z))) = 1 := by exact (map_sum (X.presheaf.germ V x hxV).hom _ _).symm.trans ((congrArg (X.presheaf.germ V x hxV) hsum).trans (X.presheaf.germ V x hxV).hom.map_one) obtain ⟨i, _, hi⟩ := IsLocalRing.exists_of_isUnit_sum (hsum' ▸ isUnit_one) have hc : IsUnit (X.presheaf.germ ⊤ x trivial (endValue (schemeInclusion i ≫ f))) := by let si : O X ⟶ O X := schemeInclusion i ≫ f let a : Γ(X,V) := Scheme.Modules.Hom.app (freeProjection (X := X) i) V z have ht := end_apply si V a have hi' : IsUnit (X.presheaf.germ V x hxV (a * (show Γ(X,V) from si.app V (1 : Γ(X,V))))) := ht ▸ hi have hc' : IsUnit (X.presheaf.germ V x hxV (show Γ(X,V) from si.app V (1 : Γ(X,V)))) := by rw [map_mul] at hi' exact isUnit_of_mul_isUnit_right hi' have hcoeff := congrArg (fun z : Γ(X,V) => X.presheaf.germ V x hxV z) (end_naturality si V) rw [X.presheaf.germ_res_apply] at hcoeff exact hcoeff ▸ hc' apply Opens.mem_iSup.mpr refine ⟨i, ?_⟩ erw [isoOpen_eq_basicOpen (Iso.refl (O X))] change x ∈ X.basicOpen (endValue (schemeInclusion i ≫ f)) exact (X.mem_basicOpen (endValue (schemeInclusion i ≫ f)) x (show x ∈ (⊤ : X.Opens) from trivial)).mpr hc def generatorSection (L : LineBundle X) (G : L.sheaf.GeneratingSections) (i : G.I) : GlobalSections X L.sheaf := schemeInclusion i ≫ G.π theorem generators_sectionOpen_cover (L : LineBundle X) (G : L.sheaf.GeneratingSections) [G.IsFiniteType] : (⨆ i : G.I, sectionOpen X (generatorSection L G i)) = ⊤ := by apply top_unique intro x _ obtain ⟨U, hx, ⟨e⟩⟩ := L.locallyRankOne x let F : SheafOfModules X.ringCatSheaf ⥤ SheafOfModules U.toScheme.ringCatSheaf := Scheme.Modules.restrictFunctor U.ι have : PreservesColimitsOfSize.{0,0} F := inferInstanceAs (PreservesColimitsOfSize.{0,0} (Scheme.Modules.restrictFunctor U.ι)) let η := (Scheme.Modules.restrictUnitIso U.ι).symm let f : schemeFree U.toScheme G.I ⟶ O U.toScheme := (SheafOfModules.mapFreeIso F G.I η).hom ≫ F.map G.π ≫ e.hom have hπ : Epi (F.map G.π) := @Functor.map_epi _ _ _ _ F _ _ _ G.π G.epi have : Epi f := @epi_iso_comp _ _ _ _ _ _ (SheafOfModules.mapFreeIso F G.I η) (F.map G.π) e hπ let : Finite G.I := (inferInstance : G.IsFiniteType).finite have hf := unit_epimorphism_cover f obtain ⟨i, hi⟩ := Opens.mem_iSup.mp (show (⟨x,hx⟩ : U.toScheme) ∈ ⨆ i : G.I, isoOpen (schemeInclusion i ≫ f) by rw [hf]; trivial) have he : schemeInclusion i ≫ f = restrictSection U.ι (generatorSection L G i) ≫ e.hom := by dsimp only [f, generatorSection, restrictSection] erw [← Category.assoc, ← Category.assoc, SheafOfModules.ιFree_mapFreeIso_hom] erw [F.map_comp] exact Category.assoc _ _ _ erw [he, isoOpen_postcomp, isoOpen_restrictSection] at hi exact Opens.mem_iSup.mpr ⟨i, hi⟩ theorem exists_fin_section_cover (L : LineBundle X) (G : L.sheaf.GeneratingSections) [G.IsFiniteType] : ∃ k : ℕ, ∃ s : Fin k → GlobalSections X L.sheaf, (⨆ i, sectionOpen X (s i)) = ⊤ := by let : Finite G.I := (inferInstance : G.IsFiniteType).finite let : Fintype G.I := Fintype.ofFinite G.I let e := (Fintype.equivFin G.I).symm exact ⟨Fintype.card G.I, fun i => generatorSection L G (e i), (e.iSup_comp (g := fun i => sectionOpen X (generatorSection L G i))).trans (generators_sectionOpen_cover L G)⟩ theorem ample_eventual_fin_section_cover [NoetherianSpace X] (L : LineBundle X) (hL : L.IsAmple) : ∃ N : ℕ, ∀ n ≥ N, ∃ k : ℕ, ∃ s : Fin k → GlobalSections X (modulePow X L.sheaf n), (⨆ i, sectionOpen X (s i)) = ⊤ := by obtain ⟨N, hN⟩ := AmpleGlobalGeneration.ample_eventual_power_global_generators L hL refine ⟨N, fun n hn => ?_⟩ obtain ⟨G, hG⟩ := hN n hn let : G.IsFiniteType := hG exact @exists_fin_section_cover X (L.pow n) G hG end end PiExponent.GeneratorsSectionCover end OAI