Skip to content

Commit c0cf536

Browse files
author
Release Manager
committed
gh-35025: Implement __getitem__ and alias weight methods for quasimodular forms <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> ### 📚 Description <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If it resolves an open issue, please link to the issue here. For example "Closes #1337" --> This PR implements a `__getitem__` method for quasimodular forms ring elements to access their components of a fixed degree. Moreover, the PR defines the alias `degree = weight` (which is the right nomenclature for elements of a graded algebra, as discussed with @fchapoton). @videlec ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [ ] I have linked an issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open pull requests that this PR logically depends on --> <!-- - #xyz: short description why this is a dependency - #abc: ... --> URL: #35025 Reported by: David Ayotte Reviewer(s):
2 parents 3585296 + b1d02c5 commit c0cf536

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/sage/modular/quasimodform/element.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from sage.structure.element import ModuleElement
2525
from sage.structure.richcmp import richcmp, op_NE, op_EQ
2626

27+
from sage.rings.integer import Integer
2728
from sage.rings.polynomial.polynomial_element import Polynomial
2829
from sage.rings.integer_ring import ZZ
2930

@@ -506,7 +507,8 @@ def weight(self):
506507
r"""
507508
Return the weight of the given quasimodular form.
508509
509-
Note that the given form must be homogeneous.
510+
Note that the given form must be homogeneous. An alias of this method is
511+
``degree``.
510512
511513
EXAMPLES::
512514
@@ -517,6 +519,8 @@ def weight(self):
517519
6
518520
sage: QM(1/2).weight()
519521
0
522+
sage: (QM.0).degree()
523+
2
520524
sage: (QM.0 + QM.1).weight()
521525
Traceback (most recent call last):
522526
...
@@ -529,6 +533,8 @@ def weight(self):
529533
raise ValueError("the given graded quasiform is not an homogeneous \
530534
element")
531535

536+
degree = weight # alias
537+
532538
def homogeneous_components(self):
533539
r"""
534540
Return a dictionary where the values are the homogeneous components of
@@ -574,6 +580,49 @@ def homogeneous_components(self):
574580
components[ZZ(k + 2*i)] = QM(forms[k]*(E2**i))
575581
return components
576582

583+
def __getitem__(self, weight):
584+
r"""
585+
Return the homogeneous component of the given quasimodular form ring
586+
element.
587+
588+
An alias of this method is ``homogeneous_component``.
589+
590+
EXAMPLES::
591+
592+
sage: QM = QuasiModularForms(1)
593+
sage: E2, E4, E6 = QM.gens()
594+
sage: F = E2 + E4*E6 + E2^3*E6
595+
sage: F[2]
596+
1 - 24*q - 72*q^2 - 96*q^3 - 168*q^4 - 144*q^5 + O(q^6)
597+
sage: F[10]
598+
1 - 264*q - 135432*q^2 - 5196576*q^3 - 69341448*q^4 - 515625264*q^5 + O(q^6)
599+
sage: F[12]
600+
1 - 576*q + 21168*q^2 + 308736*q^3 - 15034608*q^4 - 39208320*q^5 + O(q^6)
601+
sage: F[4]
602+
0
603+
sage: F.homogeneous_component(2)
604+
1 - 24*q - 72*q^2 - 96*q^3 - 168*q^4 - 144*q^5 + O(q^6)
605+
606+
TESTS::
607+
608+
sage: F[x]
609+
Traceback (most recent call last):
610+
...
611+
KeyError: 'the weight must be an integer'
612+
sage: F[-1]
613+
Traceback (most recent call last):
614+
...
615+
ValueError: the weight must be nonnegative
616+
"""
617+
if not isinstance(weight, (int, Integer)):
618+
raise KeyError("the weight must be an integer")
619+
if weight < 0:
620+
raise ValueError("the weight must be nonnegative")
621+
return self.homogeneous_components().get(weight, self.parent().zero())
622+
623+
homogeneous_component = __getitem__ # alias
624+
625+
577626
def serre_derivative(self):
578627
r"""
579628
Return the Serre derivative of the given quasimodular form.

0 commit comments

Comments
 (0)