Jason Grout wrote:
> Wilfried_Huss wrote:
>>
>> On 19 Mrz., 16:47, Jason Grout <jason-s...@creativetrax.com> wrote:
>>> ma...@mendelu.cz wrote:
>>>> Hello, this command produces one half of a cirle, not 1/4 as excepted.
>>>> I think that this is a bug in sage 3.4
>>>> Robert
>>>> region_plot([y>0,x>0,x^2+y^2<3], (-3, 3), (-3,
>>>> 3),plot_points=100,incol='gray').show(aspect_ratio=1)
>>> I get a quarter-circle on my sage 3.4 and on sagenb.org.  Can you try on
>>> sagenb.org?
>> This works:
>> sage: var('x,y')
>> sage: region_plot([y>0,x>0,x^2+y^2<3], (x, -3, 3), (y, -3,3))
>>
>> But if one leaves out the variables, one gets an half circle:
>> sage: region_plot([y>0,x>0,x^2+y^2<3], (-3, 3), (-3,3))
>>
>> I've written a patch which fixes this:
>> http://trac.sagemath.org/sage_trac/ticket/5567
> 
> 
> Ah, yes, good catch.  For those that want to know, Sage was interpreting 
> the first two constraints as functions of one variable, so when it 
> plugged in two numbers, Sage behaved as though you had typed x>0, x>0. 
> When I did my example, I explicitly put in the variable names (it's a 
> good habit to be explicit in plotting), so I got the right plot.
> 
> There should be a standard function that takes a tuple of functions and 
> returns a list of variables for all the functions.  This is used all 
> over the plotting code, the fast_callable code, now this code, etc. 
> Basically, there should be a function that, treating a tuple of 
> functions as a vector-valued function, returns the variables used in the 
> vector-valued function.
> 
> Also, I wonder why fast_float is not used?  It could drastically speed 
> up plots.  You could just replace the lines like:
> 
> s = symbolic_expression(f.rhs() - f.lhs()).function(*variables)
> 
> with
> 
> s = fast_float(f.rhs() - f.lhs(), *vars)
> 
> and you'd probably see at least an order of magnitude speedup.  (make 
> sure to do "from sage.ext.fast_eval import fast_float" first).
> 


Actually, I believe that the call to setup_eval_on_grid automatically 
does the call to fast_float, so it's probably already happening and we 
don't have to worry about anything.

In fact, I think the root of the problem is in 
plot/plot3d/parametric_plot3d.py in the adapt_to_callable function (this 
is called by setup_for_eval_on_grid, which is in turn called by 
region_plot).  Observe (and please pardon my debugging in public :)


sage: from sage.plot.plot3d.parametric_plot3d import adapt_to_callable
sage: var('x,y')
(x, y)
sage: funcs = [x,y]
sage: adapt_to_callable(funcs,2)

((<sage.ext.interpreters.wrapper_rdf.Wrapper_rdf object at 0xa9b1d9c>,
   <sage.ext.interpreters.wrapper_rdf.Wrapper_rdf object at 0xa9d916c>),
  (y, x))


First of all, why in the world are the arguments y, then x?  I thought 
the convention was alphabetical ordering if an ordering wasn't specified.

Well, the problem is in this line of adapt_to_callable:

tuple(sorted(set(sum( [z.variables() for z in f], ()) )))

Note:

sage: sorted(set(sum([z.variables() for z in funcs],())))
[y, x]

and even

sage: sorted(list(set(sum([z.variables() for z in funcs],()))))
[y, x]


For some reason, sorting the list [y,x] doesn't make it [x,y]:

sage: sorted([y,x])
[y, x]


There seem to be other problems too:

sage: funcs=[x,y,1]
sage: adapt_to_callable(funcs,2)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/jason/.sage/temp/littleone/16993/_home_jason__sage_init_sage_0.py 
in <module>()

/home/jason/sage/local/lib/python2.5/site-packages/sage/plot/plot3d/parametric_plot3d.pyc
 
in adapt_to_callable(f, nargs)
     620     except TypeError:
     621         vars = ()
--> 622         f = [fast_float_constant(x) for x in f]
     623
     624     if nargs is not None and len(vars) != nargs:

/home/jason/sage/local/lib/python2.5/site-packages/sage/ext/fast_eval.so 
in sage.ext.fast_eval.fast_float_constant (sage/ext/fast_eval.c:6827)()

/home/jason/sage/local/lib/python2.5/site-packages/sage/ext/fast_eval.so 
in sage.ext.fast_eval.FastDoubleFunc.__init__ (sage/ext/fast_eval.c:2781)()

TypeError: a float is required


This comes from assuming that if any of the functions doesn't have a 
.variables() method, then *all* of the functions must be constants. 
That seems a bit silly...

So I think it not a coincidence that this function has no doctests.  I 
think this is yet another example of code that doesn't have doctests 
that (not surprisingly) is broken.

Wilfried, can you take a look at this function (adapt_to_callable)?  I 
think fixing it will fix probably lots of other bugs as well, since it 
is called from lots of plotting code.

Thanks,

Jason


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to