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

Commit

Permalink
updated _generators_variables_dictionnary
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAyotte committed Jul 7, 2021
1 parent 5bbc4f4 commit b2517ec
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/sage/modular/modform/find_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from random import shuffle
from sage.combinat.integer_vector_weighted import WeightedIntegerVectors
from sage.rings.polynomial.multi_polynomial import MPolynomial
from sage.rings.polynomial.polynomial_element import Polynomial
#from sage.symbolic.expression import Expression

from sage.structure.parent import Parent
Expand Down Expand Up @@ -390,18 +391,18 @@ def _generators_variables_dictionnary(self, pol, gen=None):
sage: M._generators_variables_dictionnary('e')
Traceback (most recent call last):
...
TypeError: `pol` should be a multivariate polynomial
TypeError: `pol` must be a polynomial
"""
if not isinstance(pol, MPolynomial):
raise TypeError("`pol` should be a multivariate polynomial")
if not isinstance(pol, (Polynomial, MPolynomial)):
raise TypeError("`pol` must be a polynomial")
if pol.base_ring() != self.base_ring():
raise ValueError("the base ring of `pol` must be the same as the base ring of the modular forms ring")
nb_gens = pol.parent().ngens()
if nb_gens != self.ngens():
raise ValueError("the given polynomial should be a multivarate polynomial of %s variables"%(self.ngens()))
nb_var = pol.parent().ngens()
if nb_var > self.ngens():
raise ValueError("the number of variables of the given polynomial (%s) cannot exceed the number of generators of the modular forms ring (%s)"%(nb_var, self.ngens()))
if gen is None:
gen = self.gen_forms()
return {pol.parent().gen(i) : self.gen(i) for i in range(0, nb_gens)}
return {pol.parent().gen(i) : self.gen(i) for i in range(0, nb_var)}

def from_polynomial(self, pol, gen=None):
r"""
Expand Down Expand Up @@ -434,11 +435,9 @@ def from_polynomial(self, pol, gen=None):
..TODO::
* add conversion for symbolic expressions?
* allow polynomials with less variables and extend if needed?
"""
dict = self._generators_variables_dictionnary(pol, gen)
return pol.substitute(dict)


def _element_constructor_(self, forms_datas):
r"""
Expand Down Expand Up @@ -510,7 +509,7 @@ def _element_constructor_(self, 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_datas.group(), forms_datas.base_ring(), self))
elif forms_datas in self.base_ring():
forms_dictionary = {0:forms_datas}
elif isinstance(forms_datas, MPolynomial):
elif isinstance(forms_datas, (Polynomial, MPolynomial)):
return self.from_polynomial(forms_datas)
else:
raise TypeError('the defining data structure should be a single modular form, a ring element, a list of modular forms, a polynomial or a dictionary')
Expand Down

0 comments on commit b2517ec

Please sign in to comment.