import OAI.NumberTheory.PiExponent.Geometry.LineBundleTensor namespace OAI universe u namespace PiExponentSeshadri.Frames noncomputable section open AlgebraicGeometry CategoryTheory TopologicalSpace open scoped AlgebraicGeometry variable {X Y Z : Scheme.{u}} def O (X : Scheme.{u}) : X.Modules := SheafOfModules.unit X.ringCatSheaf def endValue (f : O X ⟶ O X) : Γ(X, ⊤) := f.app ⊤ (1 : Γ(X, ⊤)) lemma end_apply (f : O X ⟶ O X) (U : X.Opens) (a : Γ(X, U)) : f.app U a = a * (show Γ(X, U) from f.app U (1 : Γ(X, U))) := by have h := f.app_smul (r := a) (x := (1 : Γ(X, U))) change f.app U (a * 1 : Γ(X, U)) = a * (show Γ(X, U) from f.app U (1 : Γ(X, U))) at h simpa only [mul_one] using h @[simp] lemma endValue_id : endValue (𝟙 (O X)) = 1 := rfl lemma endValue_comp (f g : O X ⟶ O X) : endValue (f ≫ g) = endValue f * endValue g := by exact end_apply g ⊤ (endValue f) def frameChange {M : X.Modules} (e f : M ≅ O X) : Γ(X, ⊤)ˣ where val := endValue (e.inv ≫ f.hom) inv := endValue (f.inv ≫ e.hom) val_inv := by rw [← endValue_comp]; simp inv_val := by rw [← endValue_comp]; simp def coefficient {M : X.Modules} (e : M ≅ O X) (s : O X ⟶ M) : Γ(X, ⊤) := endValue (s ≫ e.hom) lemma coefficient_change {M : X.Modules} (e f : M ≅ O X) (s : O X ⟶ M) : coefficient f s = (frameChange e f : Γ(X, ⊤)) * coefficient e s := by change endValue (s ≫ f.hom) = endValue (e.inv ≫ f.hom) * endValue (s ≫ e.hom) rw [mul_comm, ← endValue_comp] simp lemma coefficient_frame {M : X.Modules} (e : M ≅ O X) : coefficient e e.inv = 1 := by simp [coefficient] def restrictSection (φ : Y ⟶ X) [IsOpenImmersion φ] {M : X.Modules} (s : O X ⟶ M) : O Y ⟶ M.restrict φ := (Scheme.Modules.restrictUnitIso φ).inv ≫ (Scheme.Modules.restrictFunctor φ).map s def restrictFrame (φ : Y ⟶ X) [IsOpenImmersion φ] {M : X.Modules} (e : M ≅ O X) : M.restrict φ ≅ O Y := (Scheme.Modules.restrictFunctor φ).mapIso e ≪≫ Scheme.Modules.restrictUnitIso φ lemma end_naturality (f : O X ⟶ O X) (U : X.Opens) : f.app U (1 : Γ(X, U)) = X.presheaf.map (homOfLE (show U ≤ ⊤ from le_top)).op (endValue f) := by have h := CategoryTheory.congr_fun (f.mapPresheaf.naturality (homOfLE (show U ≤ ⊤ from le_top)).op) (1 : Γ(X, ⊤)) change f.app U (X.presheaf.map (homOfLE (show U ≤ ⊤ from le_top)).op (1 : Γ(X, ⊤))) = X.presheaf.map (homOfLE (show U ≤ ⊤ from le_top)).op (endValue f) at h simpa only [map_one] using h lemma endValue_restrict (φ : Y ⟶ X) [IsOpenImmersion φ] (f : O X ⟶ O X) : endValue (restrictSection φ f ≫ (Scheme.Modules.restrictUnitIso φ).hom) = φ.appTop (endValue f) := by change (φ.appIso ⊤).hom (f.app (φ ''ᵁ ⊤) ((φ.appIso ⊤).inv 1)) = _ rw [map_one, end_naturality] change (X.presheaf.map (homOfLE (show φ ''ᵁ ⊤ ≤ ⊤ from le_top)).op ≫ (φ.appIso ⊤).hom) (endValue f) = _ rw [Scheme.Hom.appIso_hom'] simp only [Scheme.Hom.appTop, Scheme.Hom.appLE, Scheme.Hom.naturality_assoc, ← Functor.map_comp] congr 1 rw [show ((Opens.map φ.base).map (homOfLE (show φ ''ᵁ ⊤ ≤ ⊤ from le_top)).op.unop).op ≫ (homOfLE (show (⊤ : Y.Opens) ≤ φ ⁻¹ᵁ (φ ''ᵁ ⊤) from by intro x _; exact ⟨x, Set.mem_univ _, rfl⟩)).op = 𝟙 _ from Subsingleton.elim _ _] erw [CategoryTheory.Functor.map_id, Category.comp_id] lemma coefficient_restrict (φ : Y ⟶ X) [IsOpenImmersion φ] {M : X.Modules} (e : M ≅ O X) (s : O X ⟶ M) : coefficient (restrictFrame φ e) (restrictSection φ s) = φ.appTop (coefficient e s) := by change endValue ((Scheme.Modules.restrictUnitIso φ).inv ≫ (Scheme.Modules.restrictFunctor φ).map s ≫ (Scheme.Modules.restrictFunctor φ).map e.hom ≫ (Scheme.Modules.restrictUnitIso φ).hom) = _ erw [← Functor.map_comp_assoc] exact endValue_restrict φ (s ≫ e.hom) lemma restrictUnit_comp (φ : Y ⟶ X) (ψ : X ⟶ Z) [IsOpenImmersion φ] [IsOpenImmersion ψ] : (Scheme.Modules.restrictUnitIso (φ ≫ ψ)).inv ≫ (Scheme.Modules.restrictFunctorComp φ ψ).hom.app (O Z) = (Scheme.Modules.restrictUnitIso φ).inv ≫ (Scheme.Modules.restrictFunctor φ).map (Scheme.Modules.restrictUnitIso ψ).inv := by ext U a change Z.presheaf.map (eqToHom (show ψ ''ᵁ (φ ''ᵁ U) = (φ ≫ ψ) ''ᵁ U from by simp)).op ((φ ≫ ψ).appIso U |>.inv |>.hom |>.toFun <| a) = (ψ.appIso (φ ''ᵁ U)).inv ((φ.appIso U).inv a) rw [Scheme.Hom.comp_appIso] simp only [Iso.trans_inv, Functor.mapIso_inv, Iso.op_inv, eqToIso.inv] change ( (φ.appIso U).inv ≫ (ψ.appIso (φ ''ᵁ U)).inv ≫ Z.presheaf.map _ ≫ Z.presheaf.map _) a = _ rw [← CategoryTheory.Functor.map_comp] simp rfl lemma restrictSection_comp (φ : Y ⟶ X) (ψ : X ⟶ Z) [IsOpenImmersion φ] [IsOpenImmersion ψ] {M : Z.Modules} (s : O Z ⟶ M) : restrictSection (φ ≫ ψ) s ≫ (Scheme.Modules.restrictFunctorComp φ ψ).hom.app M = restrictSection φ (restrictSection ψ s) := by let F := Scheme.Modules.restrictFunctor φ let G := Scheme.Modules.restrictFunctor ψ let H := Scheme.Modules.restrictFunctor (φ ≫ ψ) let e := Scheme.Modules.restrictFunctorComp φ ψ let a : O Y ⟶ H.obj (O Z) := (Scheme.Modules.restrictUnitIso (φ ≫ ψ)).inv let b : O Y ⟶ F.obj (O X) := (Scheme.Modules.restrictUnitIso φ).inv let c : O X ⟶ G.obj (O Z) := (Scheme.Modules.restrictUnitIso ψ).inv change (a ≫ H.map s) ≫ e.hom.app M = b ≫ F.map (c ≫ G.map s) calc _ = a ≫ (H.map s ≫ e.hom.app M) := Category.assoc _ _ _ _ = a ≫ (e.hom.app (O Z) ≫ F.map (G.map s)) := congrArg (fun t => a ≫ t) (e.hom.naturality s) _ = (a ≫ e.hom.app (O Z)) ≫ F.map (G.map s) := (Category.assoc _ _ _).symm _ = (b ≫ F.map c) ≫ F.map (G.map s) := congrArg (fun t => t ≫ F.map (G.map s)) (restrictUnit_comp φ ψ) _ = b ≫ (F.map c ≫ F.map (G.map s)) := Category.assoc _ _ _ _ = _ := congrArg (fun t => b ≫ t) (F.map_comp c (G.map s)).symm lemma coefficient_transport {M N : X.Modules} (e : M ≅ N) (f : N ≅ O X) (s : O X ⟶ M) : coefficient (e ≪≫ f) s = coefficient f (s ≫ e.hom) := by simp only [coefficient, Iso.trans_hom, Category.assoc] lemma coefficient_restrict_comp (φ : Y ⟶ X) (ψ : X ⟶ Z) [IsOpenImmersion φ] [IsOpenImmersion ψ] {M : Z.Modules} (e : M.restrict ψ ≅ O X) (s : O Z ⟶ M) : coefficient ((Scheme.Modules.restrictFunctorComp φ ψ).app M ≪≫ restrictFrame φ e) (restrictSection (φ ≫ ψ) s) = φ.appTop (coefficient e (restrictSection ψ s)) := by rw [coefficient_transport] change coefficient (restrictFrame φ e) (restrictSection (φ ≫ ψ) s ≫ (Scheme.Modules.restrictFunctorComp φ ψ).hom.app M) = _ rw [restrictSection_comp, coefficient_restrict] lemma restrictSection_congr {φ ψ : Y ⟶ X} (h : φ = ψ) [IsOpenImmersion φ] [IsOpenImmersion ψ] {M : X.Modules} (s : O X ⟶ M) : restrictSection φ s ≫ (Scheme.Modules.restrictFunctorCongr h).hom.app M = restrictSection ψ s := by subst ψ have H : (Scheme.Modules.restrictFunctorCongr (show φ = φ from rfl)).hom.app M = 𝟙 _ := by ext U a simp rfl rw [H, Category.comp_id] lemma overlap_coefficients {W : Scheme.{u}} (φ : Y ⟶ X) (ψ : Z ⟶ X) (a : W ⟶ Y) (b : W ⟶ Z) [IsOpenImmersion φ] [IsOpenImmersion ψ] [IsOpenImmersion a] [IsOpenImmersion b] (h : a ≫ φ = b ≫ ψ) {M : X.Modules} (e : M.restrict φ ≅ O Y) (f : M.restrict ψ ≅ O Z) : ∃ c : Γ(W, ⊤)ˣ, ∀ s : O X ⟶ M, b.appTop (coefficient f (restrictSection ψ s)) = (c : Γ(W, ⊤)) * a.appTop (coefficient e (restrictSection φ s)) := by let E : M.restrict (a ≫ φ) ≅ O W := (Scheme.Modules.restrictFunctorComp a φ).app M ≪≫ restrictFrame a e let F : M.restrict (a ≫ φ) ≅ O W := (Scheme.Modules.restrictFunctorCongr h).app M ≪≫ (Scheme.Modules.restrictFunctorComp b ψ).app M ≪≫ restrictFrame b f refine ⟨frameChange E F, fun s => ?_⟩ have H := coefficient_change E F (restrictSection (a ≫ φ) s) have hE : coefficient E (restrictSection (a ≫ φ) s) = a.appTop (coefficient e (restrictSection φ s)) := coefficient_restrict_comp a φ e s have hF : coefficient F (restrictSection (a ≫ φ) s) = b.appTop (coefficient f (restrictSection ψ s)) := by change coefficient ((Scheme.Modules.restrictFunctorCongr h).app M ≪≫ ((Scheme.Modules.restrictFunctorComp b ψ).app M ≪≫ restrictFrame b f)) _ = _ rw [coefficient_transport] change coefficient _ (restrictSection (a ≫ φ) s ≫ (Scheme.Modules.restrictFunctorCongr h).hom.app M) = _ rw [restrictSection_congr] exact coefficient_restrict_comp b ψ f s rwa [hE, hF] at H end end PiExponentSeshadri.Frames end OAI