# 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


8  8  from sage.plot.misc import ensure_subs 
9  9  
10  10  from sage.ext.fast_eval import fast_float, fast_float_constant, is_fast_float 
 11  import sage.calculus.calculus 
11  12  
12  13  def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", **kwds): 
13  14  r""" 
… 
… 

343  344  Traceback (most recent call last): 
344  345  ... 
345  346  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)) 
346  351  """ 
347  352  # TODO: 
348  353  # * Surface  behavior of functions not defined everywhere  see note above 
… 
… 

442  447  g, (u,v) = adapt_to_callable(f, 2) 
443  448  except TypeError: 
444  449  g = tuple(f) 
445   
 450  
446  451  else: 
447  452  if v is None: 
448  453  raise ValueError, "both ranges must specify a variable or neither must" 
… 
… 

490  495  function, expected arguments 
491  496  """ 
492  497  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: 
498  503  # Otherwise any free variable names in any order 
499  504  try: 
500   vars = s.variables() 
 505  vars = list(set(sum([z.variables() for z in f], ()))) 
 506  vars.sort() 
501  507  except AttributeError: 
502  508  vars = () 
503  509  f = [fast_float_constant(x) for x in f] 