Updates:
        Cc: asmeurer

Comment #3 on issue 1705 by smichr: [PATCH] _separatevars_dict: Fix issue  
where unintended symbols would be selected
http://code.google.com/p/sympy/issues/detail?id=1705

I looked at this and things look good. Since this function is being edited  
(and since
there were a few typos in the docstring) could I suggest the following  
edited version?

---
     Separates variables in an expression, if possible.  By default, it  
separates
     with respect to all symbols in an expression and collects constant
     coefficients that are independent of symbols.  If dict=True then only  
those
     symbols specified by `symbols` will be separated and keyed to their
     respective symbol in the dictionary; any part that has no symbol (or  
none
     of those specified) will be returned with key 'coeff'.

     Note that if the expression is not really separable, or is only  
partially
     separable it will do the best it can to separate it.  It does not throw  
any
     errors if the expression is not separable.  It just returns the  
expression.
     If dict=True and the expression is not separable, then None is returned.

     Also, note that the order of the factors is determined by Mul, so that  
the
     separated expressions may not necessarily be grouped together.

---

Also, might I suggest that the one example with x, y, z and the dictionary  
be changed
to the following to demonstrate that symbols not specified will be grouped  
into coef:

>>> separatevars(2*x**2*z*sin(y)+2*z*x**2, dict=True, symbols=(x, y))
{'coeff': 2*z, x: x**2, y: 1 + sin(y)}

And finally, that a filter of given symbols be done so only symbols are  
returned in
the dictionary. If this isn't done (and someone uses atoms() instead of
atoms(Symbol)) then the dictionary will have some numerical keys...it's not  
a show
stopper, but perhaps it could be more discriminating.

e.g.

>>> var('x y z a')
(x, y, z, a)
>>> eq=3*x+a*(x+1)-a
>>> separatevars(eq, dict=True, symbols=eq.atoms())
{'coeff': 1, x: x, 1: 1, 3: 1, -1: 1, a: 3 + a}

Perhaps something in separatevars like

     if dict:
         symbols = [x for x in symbols if x.is_Symbol]
         return _separatevars_dict(_separatevars(expr), *symbols)
     else:
         return _separatevars(expr)


--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to sympy-issues@googlegroups.com
To unsubscribe from this group, send email to 
sympy-issues+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to