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

Commit

Permalink
fixed parsing for variable name in from_polynomial
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAyotte committed Aug 26, 2021
1 parent b77460b commit 7d10c2d
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/sage/modular/modform/ring.py
Expand Up @@ -29,6 +29,7 @@
from .constructor import ModularForms
from .element import is_ModularFormElement, GradedModularFormElement
from .space import is_ModularFormsSpace
from .defaults import DEFAULT_VARIABLE
from random import shuffle

from sage.rings.polynomial.multi_polynomial import MPolynomial
Expand Down Expand Up @@ -385,8 +386,10 @@ def from_polynomial(self, pol, gens=None):
INPUT:
- ``pol`` -- A multivariate polynomial
- ``gens`` -- list (default: ``None``) of generators of the modular forms ring
- ``pol`` -- A multivariate polynomial. The variables names of the
polynomial should be different from ``'q'``.
- ``gens`` -- list (default: ``None``) of generators of the modular
forms ring
OUTPUT: A GradedModularFormElement given by the polynomial relation ``pol``.
Expand All @@ -408,13 +411,29 @@ def from_polynomial(self, pol, gens=None):
sage: M.from_polynomial(P(1/2))
1/2
The variable names should be different from ``'q'``::
sage: M = ModularFormsRing(1)
sage: q, t = polygens(QQ, 'q, t')
sage: M.from_polynomial(q + t)
Traceback (most recent call last):
...
ValueError: the variable name `q` is reserved for q-expansion, please use a different variable name
TESTS::
sage: x,y = polygens(GF(7), 'x, y')
sage: ModularFormsRing(1, GF(7))(x)
Traceback (most recent call last):
...
NotImplementedError: conversion from polynomial is not implemented if the base ring is not Q
sage: M = ModularFormsRing(1)
sage: q = polygen(QQ, 'q')
sage: M(q^2 + q + 1)
Traceback (most recent call last):
...
ValueError: the variable name `q` is reserved for q-expansion, please use a different variable name
..TODO::
Expand All @@ -424,6 +443,8 @@ def from_polynomial(self, pol, gens=None):
raise NotImplementedError("conversion from polynomial is not implemented if the base ring is not Q")
if not isinstance(pol, (MPolynomial, Polynomial)):
raise TypeError('`pol` must be a polynomial')
if DEFAULT_VARIABLE in pol.parent()._names:
raise ValueError('the variable name `q` is reserved for q-expansion, please use a different variable name')
if pol.is_constant():
return self(pol.constant_coefficient())
if gens is None:
Expand Down Expand Up @@ -469,12 +490,6 @@ def _element_constructor_(self, forms_datum):
Traceback (most recent call last):
...
TypeError: the defining data structure should be a single modular form, a ring element, a list of modular forms, a polynomial or a dictionary
sage: P.<q> = QQ[]
sage: f = 1 + 240*q + 2160*q^2
sage: ModularFormsRing(1)(f)
Traceback (most recent call last):
...
NotImplementedError: conversion from q-expansion not yet implemented
sage: P.<t> = PowerSeriesRing(QQ)
sage: e = 1 + 240*t + 2160*t^2 + 6720*t^3 + 17520*t^4 + 30240*t^5 + O(t^6)
sage: ModularFormsRing(1)(e)
Expand All @@ -494,8 +509,6 @@ def _element_constructor_(self, forms_datum):
elif forms_datum in self.base_ring():
forms_dictionary = {0:forms_datum}
elif isinstance(forms_datum, (Polynomial, MPolynomial)):
if forms_datum.parent()._names[0] == 'q':
raise NotImplementedError("conversion from q-expansion not yet implemented")
return self.from_polynomial(forms_datum)
elif isinstance(forms_datum, PowerSeries_poly):
raise NotImplementedError("conversion from q-expansion not yet implemented")
Expand Down

0 comments on commit 7d10c2d

Please sign in to comment.