Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
fix docstring, changed some syntax, removed _rmul_, add negative weig…
Browse files Browse the repository at this point in the history
…ht checker for __getitem__, fix weight of zero element bug
  • Loading branch information
DavidAyotte committed Jul 14, 2021
1 parent 7dbaf4e commit 5887973
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 49 deletions.
59 changes: 24 additions & 35 deletions src/sage/modular/modform/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -3078,19 +3078,22 @@ def new_level(self):
return self.L() * self.M()

class GradedModularFormElement(ModuleElement):
def __init__(self, parent, forms_datas):
r"""
The element class for ``ModularFormsRing``
"""
def __init__(self, parent, forms_datum):
r"""
An element of a graded ring of modular forms.
INPUT:
- ``parents`` - an object of the class ModularFormsRing
- ``forms_data`` - a dictionary ``{k_1:f_1, k_2:f_2, ..., k_n:f_n}`` or a list [f_1, f_2,..., f_n]
- ``parent`` - an object of the class ``ModularFormsRing``
- ``forms_datum`` - a dictionary ``{k_1:f_1, k_2:f_2, ..., k_n:f_n}`` or a list ``[f_1, f_2,..., f_n]``
where `f_i` is a modular form of weight `k_i`
OUTPUT:
A ``GradedModularFormElement`` corresponding to `f_1 + f_2 + ... f_n`
A ``GradedModularFormElement`` corresponding to `f_1 + f_2 + ... + f_n`
EXAMPLES::
Expand Down Expand Up @@ -3126,8 +3129,8 @@ def __init__(self, parent, forms_datas):
sage: TestSuite(m).run()
"""
forms_dictionary = {}
if isinstance(forms_datas, dict):
for k,f in forms_datas.items():
if isinstance(forms_datum, dict):
for k,f in forms_datum.items():
if isinstance(k, (int, Integer)):
k = ZZ(k)
if k == 0:
Expand All @@ -3147,8 +3150,8 @@ def __init__(self, parent, forms_datas):
raise ValueError('at least one value (%s) of the defining dictionary is not a `ModularFormElement`'%(f))
else:
raise ValueError('at least one key (%s) of the defining dictionary is not an integer'%(k))
elif isinstance(forms_datas, list):
for f in forms_datas:
elif isinstance(forms_datum, list):
for f in forms_datum:
if is_ModularFormElement(f):
chi = f.character(compute=False)
if (chi is not None) and (not chi.is_trivial()):
Expand Down Expand Up @@ -3305,10 +3308,16 @@ def __getitem__(self, weight):
sage: f['a']
Traceback (most recent call last):
...
KeyError: 'the weight should be an integer'
KeyError: 'the weight must be an integer'
sage: f[-1]
Traceback (most recent call last):
...
ValueError: the weight must be non-negative
"""
if not isinstance(weight, (int, Integer)):
raise KeyError("the weight should be an integer")
raise KeyError("the weight must be an integer")
if weight < 0:
raise ValueError("the weight must be non-negative")
return self._forms_dictionary.get(weight, self.parent().zero())
homogeneous_component = __getitem__ #alias

Expand Down Expand Up @@ -3357,7 +3366,7 @@ def _add_(self, other):
GM = self.__class__
f_self = self._forms_dictionary
f_other = other._forms_dictionary
f_sum = { k : f_self.get(k, 0) + f_other.get(k, 0) for k in set(f_self) | set(f_other)} #TODO: fix the error E4 + QQ(0)
f_sum = { k : f_self.get(k, 0) + f_other.get(k, 0) for k in set(f_self) | set(f_other)}
return GM(self.parent(), f_sum)

def __neg__(self):
Expand Down Expand Up @@ -3434,30 +3443,6 @@ def _lmul_(self, c):
f_mul = {k:c*f for k,f in f_self.items()}
return GM(self.parent(), f_mul)

def _rmul_(self, c):
r"""
The right action of the base ring on self.
INPUT:
- ``c`` - an element of the base ring of self
OUPUT: A ``GradedModularFormElement``.
TESTS::
sage: M = ModularFormsRing(13)
sage: f = M(ModularForms(13,6).6)
sage: f * 7 # indirect doctest
7*q + 231*q^2 + 1708*q^3 + 7399*q^4 + 21882*q^5 + O(q^6)
sage: f * 13/19 # indirect doctest
13/19*q + 429/19*q^2 + 3172/19*q^3 + 13741/19*q^4 + 40638/19*q^5 + O(q^6)
"""
GM = self.__class__
f_self = self._forms_dictionary
f_mul = {k:f*c for k,f in f_self.items()}
return GM(self.parent(), f_mul)

def _richcmp_(self, other, op):
r"""
Compare self with other.
Expand Down Expand Up @@ -3503,13 +3488,17 @@ def weight(self):
sage: D = ModularForms(1,12).0; M = ModularFormsRing(1)
sage: M(D).weight()
12
sage: M.zero().weight()
0
sage: e4 = ModularForms(1,4).0
sage: (M(D)+e4).weight()
Traceback (most recent call last):
...
ValueError: the given graded form is not homogeneous (not a modular form)
"""
if self.is_homogeneous():
if self.is_zero():
return ZZ(0)
return next(iter(self._forms_dictionary))
else:
raise ValueError("the given graded form is not homogeneous (not a modular form)")
Expand Down
26 changes: 13 additions & 13 deletions src/sage/modular/modform/find_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@ def ngens(self):
"""
return len(self.gen_forms())

def _element_constructor_(self, forms_datas):
def _element_constructor_(self, forms_datum):
r"""
The call method of self.
INPUT:
- ``forms_datas`` (dict, list, ModularFormElement, GradedModularFormElement, RingElement) - Try to coerce
``forms_datas`` into self.
- ``forms_datum`` (dict, list, ModularFormElement, GradedModularFormElement, RingElement) - Try to coerce
``forms_datum`` into self.
TESTS::
Expand Down Expand Up @@ -374,17 +374,17 @@ def _element_constructor_(self, forms_datas):
...
TypeError: the defining data structure should be a single modular form, a ring element, a list of modular forms or a dictionary
"""
if isinstance(forms_datas, (dict, list)):
forms_dictionary = forms_datas
elif isinstance(forms_datas, self.element_class):
forms_dictionary = forms_datas._forms_dictionary
elif is_ModularFormElement(forms_datas):
if forms_datas.group() == self.group() and self.base_ring().has_coerce_map_from(forms_datas.base_ring()):
forms_dictionary = {forms_datas.weight():forms_datas}
if isinstance(forms_datum, (dict, list)):
forms_dictionary = forms_datum
elif isinstance(forms_datum, self.element_class):
forms_dictionary = forms_datum._forms_dictionary
elif is_ModularFormElement(forms_datum):
if forms_datum.group() == self.group() and self.base_ring().has_coerce_map_from(forms_datum.base_ring()):
forms_dictionary = {forms_datum.weight():forms_datum}
else:
raise ValueError('the group (%s) and/or the base ring (%s) of the given modular form is not consistant with the base space: %s'%(forms_datas.group(), forms_datas.base_ring(), self))
elif forms_datas in self.base_ring():
forms_dictionary = {0:forms_datas}
raise ValueError('the group (%s) and/or the base ring (%s) of the given modular form is not consistant with the base space: %s'%(forms_datum.group(), forms_datum.base_ring(), self))
elif forms_datum in self.base_ring():
forms_dictionary = {0:forms_datum}
else:
raise TypeError('the defining data structure should be a single modular form, a ring element, a list of modular forms or a dictionary')
return self.element_class(self, forms_dictionary)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/modform/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ def _pushout_(self, other):
INPUT:
- ``other`` -- ``ModularFormSpace`` or a ``ModularFormRing``
- ``other`` -- ``ModularFormSpace`` or a ``ModularFormRing``
OUTPUT: If ``self`` and ``other`` have the same groups and base rings, then this method returns
``self`` if the weights of the two spaces are equal, otherwise it returns a ``ModularFormsRing``.
Expand Down

0 comments on commit 5887973

Please sign in to comment.