#11753: Fix step=0 in (x)srange
------------------------+---------------------------------------------------
   Reporter:  ppurka    |          Owner:  jason, was                     
       Type:  defect    |         Status:  needs_review                   
   Priority:  minor     |      Milestone:  sage-4.7.2                     
  Component:  graphics  |       Keywords:  srange xsrange division_by_zero
Work_issues:            |       Upstream:  N/A                            
   Reviewer:            |         Author:                                 
     Merged:            |   Dependencies:                                 
------------------------+---------------------------------------------------
Changes (by ppurka):

  * status:  needs_info => needs_review


Old description:

> The following command
> {{{
> plot(x,3,3)
> }}}
> generates the following error:
> {{{
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "_sage_input_4.py", line 10, in <module>
>     exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8
> -*-\\n" +
> _support_.preparse_worksheet_cell(base64.b64decode("cGxvdCh4LDMsMyk="),globals())+"\\n");
> execfile(os.path.abspath("___code___.py"))
>   File "", line 1, in <module>
>
>   File "/tmp/tmpezK4rJ/___code___.py", line 3, in <module>
>     exec compile(u'plot(x,_sage_const_3 ,_sage_const_3 )
>   File "", line 1, in <module>
>
>   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
> packages/sage/misc/decorators.py", line 573, in wrapper
>     return func(*args, **kwds)
>   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
> packages/sage/misc/decorators.py", line 432, in wrapper
>     return func(*args, **options)
>   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
> packages/sage/plot/plot.py", line 3032, in plot
>     G = funcs.plot(*args, **original_opts)
>   File "expression.pyx", line 8023, in
> sage.symbolic.expression.Expression.plot
> (sage/symbolic/expression.cpp:31185)
>   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
> packages/sage/misc/decorators.py", line 573, in wrapper
>     return func(*args, **kwds)
>   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
> packages/sage/misc/decorators.py", line 432, in wrapper
>     return func(*args, **options)
>   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
> packages/sage/plot/plot.py", line 3051, in plot
>     G = _plot(funcs, (xmin, xmax), *args, **kwds)
>   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
> packages/sage/plot/plot.py", line 3154, in _plot
>     data = generate_plot_points(f, xrange, plot_points,
> adaptive_tolerance, adaptive_recursion, randomize)
>   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
> packages/sage/plot/plot.py", line 4154, in generate_plot_points
>     data = srange(*ranges[0], include_endpoint=True)
>   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
> packages/sage/misc/misc.py", line 1149, in srange
>     L =
> list(xsrange(start,end,step,universe,check,include_endpoint,endpoint_tolerance))
>   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
> packages/sage/misc/misc.py", line 1236, in xsrange
>     count = (end-start)/step
> ZeroDivisionError: float division
> }}}
> The error seems to be in (x)srange in devel/sage/sage/misc/misc.py.
> Attached is a patch which raises a ValueError when the start point and
> end point of a plot are the same. The patches are to
> devel/sage/sage/{misc,plot}/misc.py and devel/sage/sage/plot/plot.py.

New description:

 The following command
 {{{
 plot(x,3,3)
 }}}
 generates the following error:
 {{{
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "_sage_input_4.py", line 10, in <module>
     exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8
 -*-\\n" +
 
_support_.preparse_worksheet_cell(base64.b64decode("cGxvdCh4LDMsMyk="),globals())+"\\n");
 execfile(os.path.abspath("___code___.py"))
   File "", line 1, in <module>

   File "/tmp/tmpezK4rJ/___code___.py", line 3, in <module>
     exec compile(u'plot(x,_sage_const_3 ,_sage_const_3 )
   File "", line 1, in <module>

   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
 packages/sage/misc/decorators.py", line 573, in wrapper
     return func(*args, **kwds)
   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
 packages/sage/misc/decorators.py", line 432, in wrapper
     return func(*args, **options)
   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
 packages/sage/plot/plot.py", line 3032, in plot
     G = funcs.plot(*args, **original_opts)
   File "expression.pyx", line 8023, in
 sage.symbolic.expression.Expression.plot
 (sage/symbolic/expression.cpp:31185)
   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
 packages/sage/misc/decorators.py", line 573, in wrapper
     return func(*args, **kwds)
   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
 packages/sage/misc/decorators.py", line 432, in wrapper
     return func(*args, **options)
   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
 packages/sage/plot/plot.py", line 3051, in plot
     G = _plot(funcs, (xmin, xmax), *args, **kwds)
   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
 packages/sage/plot/plot.py", line 3154, in _plot
     data = generate_plot_points(f, xrange, plot_points,
 adaptive_tolerance, adaptive_recursion, randomize)
   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
 packages/sage/plot/plot.py", line 4154, in generate_plot_points
     data = srange(*ranges[0], include_endpoint=True)
   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
 packages/sage/misc/misc.py", line 1149, in srange
     L =
 
list(xsrange(start,end,step,universe,check,include_endpoint,endpoint_tolerance))
   File "/home/punarbasu/Installations/sage-4.7/local/lib/python2.6/site-
 packages/sage/misc/misc.py", line 1236, in xsrange
     count = (end-start)/step
 ZeroDivisionError: float division
 }}}
 The error seems to be in (x)srange in devel/sage/sage/misc/misc.py.
 Attached is a patch which raises a ValueError when the start point and end
 point of a plot are the same. The patches are to
 devel/sage/sage/{misc,plot}/misc.py and devel/sage/sage/plot/plot.py.

 I forgot to mention earlier: the errors that are generated with this patch
 for (x)srange() are essentially the same errors that python gives when
 (x)range() is called with step 0.

 Apply 11753-fix_div_by_zero.patch to devel/sage

--

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11753#comment:9>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to