Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement __getitem__ and alias weight methods for quasimodular forms #35025

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion src/sage/modular/quasimodform/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from sage.structure.element import ModuleElement
from sage.structure.richcmp import richcmp, op_NE, op_EQ

from sage.rings.integer import Integer
from sage.rings.polynomial.polynomial_element import Polynomial

class QuasiModularFormsElement(ModuleElement):
Expand Down Expand Up @@ -489,7 +490,8 @@ def weight(self):
r"""
Return the weight of the given quasimodular form.

Note that the given form must be homogeneous.
Note that the given form must be homogeneous. An alias of this method is
``degree``.

EXAMPLES::

Expand All @@ -500,6 +502,8 @@ def weight(self):
6
sage: QM(1/2).weight()
0
sage: (QM.0).degree()
2
sage: (QM.0 + QM.1).weight()
Traceback (most recent call last):
...
Expand All @@ -510,6 +514,8 @@ def weight(self):
else:
raise ValueError("the given graded quasiform is not an homogeneous element")

degree = weight # alias

def homogeneous_components(self):
r"""
Return a dictionary where the values are the homogeneous components of
Expand Down Expand Up @@ -538,6 +544,49 @@ def homogeneous_components(self):
pol_hom_comp = poly_self.homogeneous_components()
return {k: QM.from_polynomial(pol) for k, pol in pol_hom_comp.items()}

def __getitem__(self, weight):
r"""
Return the homogeneous component of the given quasimodular form ring
element.

An alias of this method is ``homogeneous_component``.

EXAMPLES::

sage: QM = QuasiModularForms(1)
sage: E2, E4, E6 = QM.gens()
sage: F = E2 + E4*E6 + E2^3*E6
sage: F[2]
1 - 24*q - 72*q^2 - 96*q^3 - 168*q^4 - 144*q^5 + O(q^6)
sage: F[10]
1 - 264*q - 135432*q^2 - 5196576*q^3 - 69341448*q^4 - 515625264*q^5 + O(q^6)
sage: F[12]
1 - 576*q + 21168*q^2 + 308736*q^3 - 15034608*q^4 - 39208320*q^5 + O(q^6)
sage: F[4]
0
sage: F.homogeneous_component(2)
1 - 24*q - 72*q^2 - 96*q^3 - 168*q^4 - 144*q^5 + O(q^6)

TESTS::

sage: F[x]
Traceback (most recent call last):
...
KeyError: 'the weight must be an integer'
sage: F[-1]
Traceback (most recent call last):
...
ValueError: the weight must be nonnegative
"""
if not isinstance(weight, (int, Integer)):
raise KeyError("the weight must be an integer")
if weight < 0:
raise ValueError("the weight must be nonnegative")
return self.homogeneous_components().get(weight, self.parent().zero())

homogeneous_component = __getitem__ # alias


def serre_derivative(self):
r"""
Return the Serre derivative of the given quasimodular form.
Expand Down