Ticket #2858: trac_2858.patch

File trac_2858.patch, 2.3 KB (added by was, 12 years ago)
  • sage/plot/plot3d/parametric_plot3d.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1232795992 28800
    # Node ID 1dcc23fa154c47fccf6c76f5f1d7c3cca23cc89d
    # Parent  0864645ddf3714e143f4e2afc0926b3c4746bf29
    trac #2858  -- parametric_plot3d throws an error when the sum of the components cancels a variable)
    
    diff -r 0864645ddf37 -r 1dcc23fa154c sage/plot/plot3d/parametric_plot3d.py
    a b  
    88from sage.plot.misc import ensure_subs
    99
    1010from sage.ext.fast_eval import fast_float, fast_float_constant, is_fast_float
     11import sage.calculus.calculus
    1112
    1213def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", **kwds):
    1314    r"""
     
    343344        Traceback (most recent call last):
    344345        ...
    345346        ValueError: plot variables should be distinct, but both are u.
     347
     348    From trac 2858:
     349        sage: parametric_plot3d((u,-u,v), (-10,10),(-10,10))
     350        sage: f(u)=u; g(v)=v^2; parametric_plot3d((g,f,f), (-10,10),(-10,10))       
    346351    """
    347352    # TODO:
    348353    #   * Surface -- behavior of functions not defined everywhere -- see note above
     
    442447            g, (u,v) = adapt_to_callable(f, 2)
    443448        except TypeError:
    444449            g = tuple(f)
    445            
     450
    446451    else:
    447452        if v is None:
    448453            raise ValueError, "both ranges must specify a variable or neither must"
     
    490495        function, expected arguments
    491496    """
    492497    try:
    493         s = sum(f) # get common universe
    494         try:
    495             # If s is callable, will return the arguments in the right order
    496             vars = s.args()
    497         except AttributeError:
     498        if sum([sage.calculus.calculus.is_CallableSymbolicExpression(z) for z in f]):
     499            # Sum to get common universe; this works since f is callable, and summing
     500            # gets the arguments in the right order.
     501            vars = sum(f).args()
     502        else:
    498503            # Otherwise any free variable names in any order
    499504            try:
    500                 vars = s.variables()
     505                vars = list(set(sum([z.variables() for z in f], ())))
     506                vars.sort()
    501507            except AttributeError:
    502508                vars = ()
    503509                f = [fast_float_constant(x) for x in f]