Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modular form plotting fails because modular forms (power series) cannot be evaluated at floats #26317

Open
alexjbest opened this issue Sep 20, 2018 · 0 comments

Comments

@alexjbest
Copy link
Contributor

If one tries to plot a modular form the plot code tries to evaluate the modular form as a function on floats, which fails. Essentially this boils down to floats not having a .parent() (see traceback at end).

There are two potential fixes, neither of which I had opportunity to test yet, but would like thoughts on:

  • Modify the line Q = a.parent() of src/sage/rings/power_series_poly.pyx to something like
         from sage.structure import parent
         Q = parent(a)

which might make power series a bit more resilient to being passed python types as input, this might be a change which should be made across a lot of Sage in that case?

  • Or modify plotting code (generate_plot_points) to not use floats, I guess this might come with some performance hit to plotting.
sage: modf = ModularForms(12).basis()[0]
sage: plot(modf)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-f871686f0b17> in <module>()
----> 1 plot(modf)

/Users/alex/sage/local/lib/python2.7/site-packages/sage/misc/decorators.pyc in wrapper(*args, **kwds)
    565                 options['__original_opts'] = kwds
    566             options.update(kwds)
--> 567             return func(*args, **options)
    568
    569         #Add the options specified by @options to the signature of the wrapped

/Users/alex/sage/local/lib/python2.7/site-packages/sage/plot/plot.pyc in plot(funcs, *args, **kwds)
   1954             xmin = kwds.pop('xmin', -1)
   1955             xmax = kwds.pop('xmax', 1)
-> 1956             G = _plot(funcs, (xmin, xmax), **kwds)
   1957
   1958         # if there is one extra arg, then it had better be a tuple

/Users/alex/sage/local/lib/python2.7/site-packages/sage/plot/plot.pyc in _plot(funcs, xrange, parametric, polar, fill, label, randomize, **options)
   2264         data = generate_plot_points(f, xrange, plot_points,
   2265                                     adaptive_tolerance, adaptive_recursion,
-> 2266                                     randomize)
   2267
   2268

/Users/alex/sage/local/lib/python2.7/site-packages/sage/plot/plot.pyc in generate_plot_points(f, xrange, plot_points, adaptive_tolerance, adaptive_recursion, randomize, initial_points)
   3862
   3863         try:
-> 3864             data[i] = (float(xi), float(f(xi)))
   3865             if str(data[i][1]) in ['nan', 'NaN', 'inf', '-inf']:
   3866                 msg = "Unable to compute f(%s)" % xi

/Users/alex/sage/local/lib/python2.7/site-packages/sage/modular/modform/element.pyc in __call__(self, x, prec)
    174             0
    175         """
--> 176         return self.q_expansion(prec)(x)
    177
    178     @cached_method

/Users/alex/sage/local/lib/python2.7/site-packages/sage/rings/power_series_poly.pyx in sage.rings.power_series_poly.PowerSeries_poly.__call__ (build/cythonized/sage/rings/power_series_poly.c:5702)()
    320             return self.__f(x)
    321
--> 322         Q = a.parent()
    323
    324         from sage.rings.padics.padic_generic import pAdicGeneric

AttributeError: 'float' object has no attribute 'parent'

Component: graphics

Keywords: plotting, modular forms, python types

Issue created by migration from https://trac.sagemath.org/ticket/26317

@alexjbest alexjbest added this to the sage-8.4 milestone Sep 20, 2018
@alexjbest alexjbest changed the title Modular form printing fails because modular forms cannot be evaluated at floats Modular form plotting fails because modular forms (power series) cannot be evaluated at floats Sep 21, 2018
@mkoeppe mkoeppe removed this from the sage-8.4 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants