From 8eb423f456f5c6ff3dee0407fff7c25067816538 Mon Sep 17 00:00:00 2001 From: DavidAyotte Date: Tue, 22 Nov 2022 18:01:08 -0500 Subject: [PATCH 1/5] src/sage/modular/quasimodform/element.py: refactor weight, homogeneous_components and is_homogeneous --- src/sage/modular/quasimodform/element.py | 65 +++++++++++++++++++----- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/src/sage/modular/quasimodform/element.py b/src/sage/modular/quasimodform/element.py index 340d8b0320e..a218e0b52a7 100644 --- a/src/sage/modular/quasimodform/element.py +++ b/src/sage/modular/quasimodform/element.py @@ -23,6 +23,7 @@ from sage.structure.richcmp import richcmp, op_NE, op_EQ from sage.rings.polynomial.polynomial_element import Polynomial +from sage.rings.integer_ring import ZZ class QuasiModularFormsElement(ModuleElement): r""" @@ -391,7 +392,7 @@ def weights_list(self): sage: QM(1/2).weights_list() [0] """ - return sorted(list(self.to_polynomial().homogeneous_components())) + return sorted(list(self.homogeneous_components().keys())) def is_homogeneous(self): r""" @@ -402,18 +403,31 @@ def is_homogeneous(self): EXAMPLES:: sage: QM = QuasiModularForms(1) - sage: (QM.0).is_homogeneous() + sage: E2, E4, E6 = QM.gens() + sage: (E2).is_homogeneous() True - sage: (QM.0 + QM.1).is_homogeneous() + sage: (E2 + E4).is_homogeneous() False - sage: (QM.0 * QM.1 + QM.2).is_homogeneous() + sage: (E2 * E4 + E6).is_homogeneous() True sage: QM(1).is_homogeneous() True - sage: (1 + QM.0).is_homogeneous() + sage: (1 + E2).is_homogeneous() False + sage: F = E6^3 + E4^4*E2 + (E4^2*E6)*E2^2 + (E4^3 + E6^2)*E2^3 + sage: F.is_homogeneous() + True """ - return len(self.weights_list()) == 1 + k = None + for i, c in enumerate(self._polynomial.coefficients(sparse=False)): + if c: + if not c.is_homogeneous(): + return False + if k is None: + k = c.weight() + 2*i + if c.weight() + 2*i != k: + return False + return True def weight(self): r""" @@ -436,9 +450,11 @@ def weight(self): ValueError: the given graded quasiform is not an homogeneous element """ if self.is_homogeneous(): - return self.to_polynomial().degree() + return (self._polynomial.leading_coefficient().weight() + + 2*self._polynomial.degree()) else: - raise ValueError("the given graded quasiform is not an homogeneous element") + raise ValueError("the given graded quasiform is not an homogeneous \ + element") def homogeneous_components(self): r""" @@ -452,15 +468,38 @@ def homogeneous_components(self): {2: 1 - 24*q - 72*q^2 - 96*q^3 - 168*q^4 - 144*q^5 + O(q^6)} sage: (QM.0 + QM.1 + QM.2).homogeneous_components() {2: 1 - 24*q - 72*q^2 - 96*q^3 - 168*q^4 - 144*q^5 + O(q^6), - 4: 1 + 240*q + 2160*q^2 + 6720*q^3 + 17520*q^4 + 30240*q^5 + O(q^6), - 6: 1 - 504*q - 16632*q^2 - 122976*q^3 - 532728*q^4 - 1575504*q^5 + O(q^6)} + 4: 1 + 240*q + 2160*q^2 + 6720*q^3 + 17520*q^4 + 30240*q^5 + O(q^6), + 6: 1 - 504*q - 16632*q^2 - 122976*q^3 - 532728*q^4 - 1575504*q^5 + O(q^6)} sage: (1 + QM.0).homogeneous_components() {0: 1, 2: 1 - 24*q - 72*q^2 - 96*q^3 - 168*q^4 - 144*q^5 + O(q^6)} + sage: QM5 = QuasiModularForms(Gamma1(3)) + sage: F = QM.1 + QM.1*QM.2 + QM.1*QM.0 + (QM.1 + QM.2^2)*QM.0^3 + sage: F.homogeneous_components() + {4: 1 + 240*q + 2160*q^2 + 6720*q^3 + 17520*q^4 + 30240*q^5 + O(q^6), + 6: 1 + 216*q - 3672*q^2 - 62496*q^3 - 322488*q^4 - 1121904*q^5 + O(q^6), + 10: 2 - 168*q - 159624*q^2 - 3756192*q^3 - 103979976*q^4 - 315731952*q^5 + O(q^6), + 18: 1 - 1080*q + 294840*q^2 - 902880*q^3 - 452402280*q^4 + 105456816*q^5 + O(q^6)} + sage: F = QM.zero() + sage: F.homogeneous_components() + {0: 0} + sage: F = QM(42/13) + sage: F.homogeneous_components() + {0: 42/13} """ QM = self.parent() - poly_self = self.to_polynomial() - pol_hom_comp = poly_self.homogeneous_components() - return {k: QM.from_polynomial(pol) for k, pol in pol_hom_comp.items()} + if self.is_zero(): + return {ZZ(0): self} + components = {} + E2 = self.parent().weight_2_eisenstein_series() + for i, c in enumerate(self._polynomial.coefficients(sparse=False)): + if c: + forms = c._forms_dictionary + for k in forms.keys(): + try: + components[ZZ(k + 2*i)] += QM(forms[k]*(E2**(2*i))) + except KeyError: + components[ZZ(k + 2*i)] = QM(forms[k]*(E2**i)) + return components def serre_derivative(self): r""" From 99b851896820f351b2e21a8a1819b5efb04ba81d Mon Sep 17 00:00:00 2001 From: DavidAyotte Date: Tue, 22 Nov 2022 18:34:19 -0500 Subject: [PATCH 2/5] src/sage/modular/quasimodform/element.py: fix small mistake --- src/sage/modular/quasimodform/element.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/modular/quasimodform/element.py b/src/sage/modular/quasimodform/element.py index a218e0b52a7..cf0e8c39ee6 100644 --- a/src/sage/modular/quasimodform/element.py +++ b/src/sage/modular/quasimodform/element.py @@ -496,7 +496,7 @@ def homogeneous_components(self): forms = c._forms_dictionary for k in forms.keys(): try: - components[ZZ(k + 2*i)] += QM(forms[k]*(E2**(2*i))) + components[ZZ(k + 2*i)] += QM(forms[k]*(E2**i)) except KeyError: components[ZZ(k + 2*i)] = QM(forms[k]*(E2**i)) return components From da7e59874b0a61d9c45a6af71d61d1cf56a1a9d5 Mon Sep 17 00:00:00 2001 From: DavidAyotte Date: Tue, 22 Nov 2022 18:36:56 -0500 Subject: [PATCH 3/5] src/sage/modular/quasimodform/element.py: fix doctest --- src/sage/modular/quasimodform/element.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/modular/quasimodform/element.py b/src/sage/modular/quasimodform/element.py index cf0e8c39ee6..e4d5ea75769 100644 --- a/src/sage/modular/quasimodform/element.py +++ b/src/sage/modular/quasimodform/element.py @@ -477,7 +477,7 @@ def homogeneous_components(self): sage: F.homogeneous_components() {4: 1 + 240*q + 2160*q^2 + 6720*q^3 + 17520*q^4 + 30240*q^5 + O(q^6), 6: 1 + 216*q - 3672*q^2 - 62496*q^3 - 322488*q^4 - 1121904*q^5 + O(q^6), - 10: 2 - 168*q - 159624*q^2 - 3756192*q^3 - 103979976*q^4 - 315731952*q^5 + O(q^6), + 10: 2 - 96*q - 149040*q^2 - 4986240*q^3 - 67535952*q^4 - 538187328*q^5 + O(q^6), 18: 1 - 1080*q + 294840*q^2 - 902880*q^3 - 452402280*q^4 + 105456816*q^5 + O(q^6)} sage: F = QM.zero() sage: F.homogeneous_components() From d5c79a74eca01a18b348fe8b7264d52077cd0d33 Mon Sep 17 00:00:00 2001 From: DavidAyotte Date: Sat, 26 Nov 2022 08:56:04 -0500 Subject: [PATCH 4/5] src/sage/modular/quasimodform/element.py: add continue statement in is_homogeneous --- src/sage/modular/quasimodform/element.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sage/modular/quasimodform/element.py b/src/sage/modular/quasimodform/element.py index e4d5ea75769..1a005a31ba7 100644 --- a/src/sage/modular/quasimodform/element.py +++ b/src/sage/modular/quasimodform/element.py @@ -425,6 +425,7 @@ def is_homogeneous(self): return False if k is None: k = c.weight() + 2*i + continue if c.weight() + 2*i != k: return False return True From 271d87dc934fc4af9d4125478e9b06bac3e1e993 Mon Sep 17 00:00:00 2001 From: DavidAyotte Date: Sat, 26 Nov 2022 08:58:29 -0500 Subject: [PATCH 5/5] src/sage/modular/quasimodform/element.py: apply suggestion --- src/sage/modular/quasimodform/element.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/modular/quasimodform/element.py b/src/sage/modular/quasimodform/element.py index 1a005a31ba7..e144d475e9e 100644 --- a/src/sage/modular/quasimodform/element.py +++ b/src/sage/modular/quasimodform/element.py @@ -392,7 +392,7 @@ def weights_list(self): sage: QM(1/2).weights_list() [0] """ - return sorted(list(self.homogeneous_components().keys())) + return sorted(self.homogeneous_components().keys()) def is_homogeneous(self): r"""