import Mathlib namespace OAI namespace PiExponent.HomogeneousSubmoduleGrading noncomputable section open DirectSum variable {R M ΟƒM : Type*} [Ring R] [AddCommGroup M] [Module R M] [SetLike ΟƒM M] [AddSubgroupClass ΟƒM M] (π“œ : β„€ β†’ ΟƒM) [DirectSum.Decomposition π“œ] (K : Submodule R M) (hK : K.IsHomogeneous π“œ) def piece (_hK : K.IsHomogeneous π“œ) (d : β„€) : AddSubgroup K where carrier := {m | (m : M) ∈ π“œ d} zero_mem' := zero_mem _ add_mem' := fun hm hn => add_mem hm hn neg_mem' := fun hm => neg_mem hm def component (m : K) (d : β„€) : piece π“œ K hK d := ⟨⟨DirectSum.decompose π“œ (m : M) d, hK d m.property⟩, (DirectSum.decompose π“œ (m : M) d).property⟩ def decompositionMap : K β†’+ ⨁ d, piece π“œ K hK d where toFun m := by classical exact DFinsupp.mk' (component π“œ K hK m) (Trunc.mk ⟨(DirectSum.decompose π“œ (m : M)).support.val, fun d => by classical by_cases hd : d ∈ (DirectSum.decompose π“œ (m : M)).support Β· exact Or.inl hd Β· right apply Subtype.ext apply Subtype.ext change (DirectSum.decompose π“œ (m : M) d : M) = 0 rw [DFinsupp.notMem_support_iff.mp hd] rfl⟩) map_zero' := by ext d change (DirectSum.decompose π“œ (0 : M) d : M) = 0 rw [DirectSum.decompose_zero] rfl map_add' m n := by ext d change (DirectSum.decompose π“œ ((m : M) + (n : M)) d : M) = (DirectSum.decompose π“œ (m : M) d : M) + (DirectSum.decompose π“œ (n : M) d : M) rw [DirectSum.decompose_add] rfl @[simp] theorem decompositionMap_apply (m : K) (d : β„€) : (((decompositionMap π“œ K hK m) d : K) : M) = (DirectSum.decompose π“œ (m : M) d : M) := rfl theorem decompositionMap_injective : Function.Injective (decompositionMap π“œ K hK) := by intro m n h apply Subtype.ext apply (DirectSum.decompose π“œ).injective ext d exact congrArg (fun z : ⨁ d, piece π“œ K hK d => ((z d : K) : M)) h theorem decompositionMap_homogeneous (d : β„€) (m : piece π“œ K hK d) : decompositionMap π“œ K hK m.val = DirectSum.of (fun d => piece π“œ K hK d) d m := by classical ext e by_cases he : d = e Β· subst e rw [DirectSum.of_eq_same] exact DirectSum.decompose_of_mem_same π“œ m.property Β· rw [DirectSum.of_eq_of_ne _ _ _ (Ne.symm he)] exact DirectSum.decompose_of_mem_ne π“œ m.property he instance decomposition : DirectSum.Decomposition (piece π“œ K hK) := by classical have hr : (decompositionMap π“œ K hK).comp (DirectSum.coeAddMonoidHom (piece π“œ K hK)) = AddMonoidHom.id _ := by apply DirectSum.addHom_ext intro d m simp only [AddMonoidHom.comp_apply, DirectSum.coeAddMonoidHom_of, AddMonoidHom.id_apply, decompositionMap_homogeneous] apply DirectSum.Decomposition.ofAddHom (piece π“œ K hK) (decompositionMap π“œ K hK) ?_ hr apply AddMonoidHom.ext intro m apply decompositionMap_injective π“œ K hK exact DFunLike.congr_fun hr (decompositionMap π“œ K hK m) theorem subtype_degree_compatible (d : β„€) (m : K) : K.subtype (DirectSum.decompose (piece π“œ K hK) m d : K) = (DirectSum.decompose π“œ (K.subtype m) d : M) := rfl variable {ΟƒR : Type*} [SetLike ΟƒR R] [AddSubgroupClass ΟƒR R] (π’œ : β„€ β†’ ΟƒR) [SetLike.GradedSMul π’œ π“œ] instance gradedSMul : SetLike.GradedSMul π’œ (piece π“œ K hK) where smul_mem := by intro i d a m ha hm change a β€’ (m : M) ∈ π“œ (i + d) exact SetLike.GradedSMul.smul_mem ha (show (m : M) ∈ π“œ d from hm) end end PiExponent.HomogeneousSubmoduleGrading end OAI