|
24 | 24 | from sage.structure.element import ModuleElement
|
25 | 25 | from sage.structure.richcmp import richcmp, op_NE, op_EQ
|
26 | 26 |
|
| 27 | +from sage.rings.integer import Integer |
27 | 28 | from sage.rings.polynomial.polynomial_element import Polynomial
|
28 | 29 |
|
29 | 30 | class QuasiModularFormsElement(ModuleElement):
|
@@ -543,6 +544,49 @@ def homogeneous_components(self):
|
543 | 544 | pol_hom_comp = poly_self.homogeneous_components()
|
544 | 545 | return {k: QM.from_polynomial(pol) for k, pol in pol_hom_comp.items()}
|
545 | 546 |
|
| 547 | + def __getitem__(self, weight): |
| 548 | + r""" |
| 549 | + Return the homogeneous component of the given quasimodular form ring |
| 550 | + element. |
| 551 | +
|
| 552 | + An alias of this method is ``homogeneous_component``. |
| 553 | +
|
| 554 | + EXAMPLES:: |
| 555 | +
|
| 556 | + sage: QM = QuasiModularForms(1) |
| 557 | + sage: E2, E4, E6 = QM.gens() |
| 558 | + sage: F = E2 + E4*E6 + E2^3*E6 |
| 559 | + sage: F[2] |
| 560 | + 1 - 24*q - 72*q^2 - 96*q^3 - 168*q^4 - 144*q^5 + O(q^6) |
| 561 | + sage: F[10] |
| 562 | + 1 - 264*q - 135432*q^2 - 5196576*q^3 - 69341448*q^4 - 515625264*q^5 + O(q^6) |
| 563 | + sage: F[12] |
| 564 | + 1 - 576*q + 21168*q^2 + 308736*q^3 - 15034608*q^4 - 39208320*q^5 + O(q^6) |
| 565 | + sage: F[4] |
| 566 | + 0 |
| 567 | + sage: F.homogeneous_component(2) |
| 568 | + 1 - 24*q - 72*q^2 - 96*q^3 - 168*q^4 - 144*q^5 + O(q^6) |
| 569 | +
|
| 570 | + TESTS:: |
| 571 | +
|
| 572 | + sage: F[x] |
| 573 | + Traceback (most recent call last): |
| 574 | + ... |
| 575 | + KeyError: 'the weight must be an integer' |
| 576 | + sage: F[-1] |
| 577 | + Traceback (most recent call last): |
| 578 | + ... |
| 579 | + ValueError: the weight must be nonnegative |
| 580 | + """ |
| 581 | + if not isinstance(weight, (int, Integer)): |
| 582 | + raise KeyError("the weight must be an integer") |
| 583 | + if weight < 0: |
| 584 | + raise ValueError("the weight must be nonnegative") |
| 585 | + return self.homogeneous_components().get(weight, self.parent().zero()) |
| 586 | + |
| 587 | + homogeneous_component = __getitem__ # alias |
| 588 | + |
| 589 | + |
546 | 590 | def serre_derivative(self):
|
547 | 591 | r"""
|
548 | 592 | Return the Serre derivative of the given quasimodular form.
|
|
0 commit comments