# HG changeset patch
# User J. H. Palmieri <palmieri@math.washington.edu>
# Date 1315939094 25200
# Node ID 356a6984b20ef87e0b0559246b5f512facd1b1cb
# Parent a48af224839e4eb2555175d15d703ecd81d0b4c1
#10750: allow solving a single equation w.r.t. more than one variable
diff git a/sage/symbolic/relation.py b/sage/symbolic/relation.py
a

b

def solve(f, *args, **kwds): 
479  479  are no solutions, return an empty list (rather than a list containing 
480  480  an empty dictionary). Likewise, if there's only a single solution, 
481  481  return a list containing one dictionary with that solution. 
482   
 482  
 483  If solving a single equation, some additional keyword arguments are available: 
 484  
 485   ``multiplicities``  bool (default: False); if True, return 
 486  corresponding multiplicities. This keyword is incompatible 
 487  with ``to_poly_solve=True`` and does not make any sense when 
 488  solving an inequality. 
 489  
 490   ``explicit_solutions``  bool (default: False); require that all 
 491  roots be explicit rather than implicit. Not used when solving 
 492  an inequality. 
 493  
 494   ``to_poly_solve``  bool (default: False) or string; use 
 495  Maxima's ``to_poly_solver`` package to search for more possible 
 496  solutions, but possibly encounter approximate solutions. This 
 497  keyword is incompatible with ``multiplicities=True`` and is not 
 498  used when solving an inequality. Setting ``to_poly_solve`` to 
 499  the string 'force' omits Maxima's solve command (useful when 
 500  finding solutions of some trigonometric equations). 
 501  
 502  For examples using these keywords, see the documentation for the 
 503  :meth:`solve <sage.symbolic.expression.Expression.solve>` method 
 504  for single equations. 
 505  
483  506  EXAMPLES:: 
484   
 507  
485  508  sage: x, y = var('x, y') 
486  509  sage: solve([x+y==6, xy==4], x, y) 
487  510  [[x == 5, y == 1]] 
… 
… 
def solve(f, *args, **kwds): 
522  545  
523  546  .. note:: 
524  547  
525   For more details about solving a single equations, see 
526   the documentation for its solve. 
 548  For more details about solving a single equation, see the 
 549  documentation for its :meth:`solve 
 550  <sage.symbolic.expression.Expression.solve>` method. 
527  551  
528  552  :: 
529  553  
… 
… 
def solve(f, *args, **kwds): 
554  578  a new variable. In the following example, ``r1`` is a real free 
555  579  variable (because of the ``r``):: 
556  580  
557   sage: solve([x+y == 3, 2*x+2*y == 6],x,y) 
 581  sage: solve(x+y == 3,x,y) 
558  582  [[x == r1 + 3, y == r1]] 
559  583  
 584  (This also illustrates solving a single equation with respect to 
 585  more than one variable.) 
 586  
560  587  Especially with trigonometric functions, the dummy variable may 
561  588  be implicitly an integer (hence the ``z``):: 
562  589  
… 
… 
def solve(f, *args, **kwds): 
646  673  [] 
647  674  """ 
648  675  from sage.symbolic.expression import is_Expression 
649   if is_Expression(f): # f is a single expression 
650   ans = f.solve(*args,**kwds) 
651   return ans 
 676  from sage.symbolic.ring import is_SymbolicVariable 
 677  # f is a single expression and there is a single variable 
 678  if is_Expression(f): 
 679  if len(args) == 1 and is_SymbolicVariable(args[0]): 
 680  ans = f.solve(*args,**kwds) 
 681  return ans 
 682  else: 
 683  f = [f] 
652  684  
653  685  if not isinstance(f, (list, tuple)): 
654  686  raise TypeError("The first argument must be a symbolic expression or a list of symbolic expressions.") 
655  687  
656  688  if len(f)==1 and is_Expression(f[0]): 
657  689  # f is a list with a single expression 
658   return f[0].solve(*args,**kwds) 
 690  if len(args) == 1 and is_SymbolicVariable(args[0]): 
 691  ans = f[0].solve(*args,**kwds) 
 692  return ans 
659  693  
660  694  # f is a list of such expressions or equations 
661   from sage.symbolic.ring import is_SymbolicVariable 
662  695  
663  696  if len(args)==0: 
664  697  raise TypeError, "Please input variables to solve for." 
665  698  if is_SymbolicVariable(args[0]): 
666  699  variables = args 
667  700  else: 
668   variables = tuple(args[0]) 
669   
 701  try: 
 702  variables = tuple(args[0]) 
 703  except TypeError: 
 704  raise TypeError, "%s is not a valid variable."%args[0] 
 705  
670  706  for v in variables: 
671  707  if not is_SymbolicVariable(v): 
672  708  raise TypeError, "%s is not a valid variable."%v 