import Mathlib namespace OAI noncomputable section namespace PiExponent open DirectSum variable {A : Type*} [CommRing A] (π’œ : β„• β†’ Submodule β„€ A) [GradedAlgebra π’œ] (S : Subring A) def subringGrade (n : β„•) : Submodule β„€ S := (π’œ n).comap S.subtype.toAddMonoidHom.toIntLinearMap theorem subringGrade_independent : iSupIndep (subringGrade π’œ S) := by have h := (DirectSum.Decomposition.isInternal π’œ).submodule_iSupIndep intro i rw [disjoint_iff_inf_le] intro x hx apply Subtype.ext apply (disjoint_iff_inf_le.mp (h i)) refine ⟨hx.1, ?_⟩ have hle : (⨆ j, ⨆ (_ : j β‰  i), subringGrade π’œ S j) ≀ (⨆ j, ⨆ (_ : j β‰  i), π’œ j).comap S.subtype.toAddMonoidHom.toIntLinearMap := by refine iSup_le fun j => iSup_le fun hj => ?_ exact Submodule.comap_mono (le_iSup_of_le j (le_iSup_of_le hj le_rfl)) exact hle hx.2 theorem subringGrade_spans (hS : βˆ€ n x, x ∈ S β†’ (decompose π’œ x n : A) ∈ S) : (⨆ n, subringGrade π’œ S n) = ⊀ := by classical apply top_unique intro x _ let c : β„• β†’ S := fun n => ⟨decompose π’œ x.1 n, hS n x.1 x.2⟩ have he : x = βˆ‘ n ∈ (decompose π’œ x.1).support, c n := by apply Subtype.ext change x.1 = S.subtype (βˆ‘ n ∈ (decompose π’œ x.1).support, c n) rw [map_sum] exact (sum_support_decompose π’œ x.1).symm rw [he] apply Submodule.sum_mem intro n hn exact (le_iSup (subringGrade π’œ S) n) (show c n ∈ subringGrade π’œ S n from (decompose π’œ x.1 n).2) @[instance_reducible] def subringGradedAlgebra (hS : βˆ€ n x, x ∈ S β†’ (decompose π’œ x n : A) ∈ S) : GradedAlgebra (subringGrade π’œ S) where one_mem := show (1 : A) ∈ π’œ 0 from SetLike.one_mem_graded π’œ mul_mem := by intro i j x y hx hy change (x.1 * y.1) ∈ π’œ (i + j) exact SetLike.mul_mem_graded hx hy toDecomposition := (DirectSum.isInternal_submodule_of_iSupIndep_of_iSup_eq_top (subringGrade_independent π’œ S) (subringGrade_spans π’œ S hS)).chooseDecomposition end PiExponent end end OAI