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

Commit

Permalink
fix constant polynomials bug
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAyotte committed Aug 4, 2021
1 parent d991d19 commit b23e726
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/sage/modular/modform/element.py
Expand Up @@ -3596,6 +3596,8 @@ def _homogeneous_to_polynomial(self, names, gens):
x0
sage: M.1._homogeneous_to_polynomial('E4, E6', gens)
E6
sage: M(1/2).to_polynomial()
1/2
sage: p = ((M.0)**3 + (M.1)**2)._homogeneous_to_polynomial('x', gens); p
x0^3 + x1^2
sage: M(p) == (M.0)**3 + (M.1)**2
Expand All @@ -3608,6 +3610,8 @@ def _homogeneous_to_polynomial(self, names, gens):
M = self.parent()
k = self.weight() #only if self is homogeneous
poly_parent = M.polynomial_ring(names, gens)
if k == 0:
return poly_parent(self[k])
monomials = M._monomials_of_weight(k, gens, poly_parent)

# initialize the matrix of coefficients
Expand Down Expand Up @@ -3664,4 +3668,4 @@ def to_polynomial(self, names='x', gens=None):
gens = M.gen_forms()

# sum the polynomial of each homogeneous part
return sum(M(self[k])._homogeneous_to_polynomial(names, gens) for k in self.weights_list())
return sum(M(self[k])._homogeneous_to_polynomial(names, gens) for k in self.weights_list())
5 changes: 5 additions & 0 deletions src/sage/modular/modform/ring.py
Expand Up @@ -444,13 +444,18 @@ def from_polynomial(self, pol, gens=None):
1 + q + q^2 + 27*q^3 + q^4 + 6*q^5 + O(q^6)
sage: M.0 + M.1 + M.2
1 + q + q^2 + 27*q^3 + q^4 + 6*q^5 + O(q^6)
sage: P = x.parent()
sage: M.from_polynomial(P(1/2))
1/2
..TODO::
* add conversion for symbolic expressions?
"""
if not isinstance(pol, (MPolynomial, Polynomial)):
raise TypeError('`pol` must be a polynomial')
if pol.is_constant():
return self(pol.constant_coefficient())
if gens is None:
gens = self.gen_forms()
dict = self._generators_variables_dictionnary(pol.parent(), gens)
Expand Down

0 comments on commit b23e726

Please sign in to comment.