Status: New Owner: asmeurer Labels: Type-Enhancement Priority-Medium Solvers EasyToFix
New issue 1572 by asmeurer: solve() should be able to solve expressions where variable only appears once http://code.google.com/p/sympy/issues/detail?id=1572 In general, you can always solve an expression for a variable if the variable only appears once in the expression. The exception of course is if the variable is inside of some function that is not invertible, such as a generic f(x) or something like gamma(x). But solve() only seems to be able to do it half of the time. >>> solve((2**exp(y**2/x) + 2)/(x**2 + 15), y) Traceback (most recent call last): File "<console>", line 1, in <module> File "./sympy/solvers/solvers.py", line 274, in solve result = tsolve(f, *symbols) File "./sympy/solvers/solvers.py", line 1502, in tsolve raise NotImplementedError("Unable to solve the equation.") NotImplementedError: Unable to solve the equation. >>> C1, C2 = symbols('C1 C2') >>> solve(C1 + C2/x**2 - exp(-f(x)), f(x)) Traceback (most recent call last): File "<console>", line 1, in <module> File "./sympy/solvers/solvers.py", line 204, in solve strategy = guess_solve_strategy(f, symbol) File "./sympy/solvers/solvers.py", line 69, in guess_solve_strategy return max([guess_solve_strategy(i, symbol) for i in expr.args]) File "./sympy/solvers/solvers.py", line 82, in guess_solve_strategy raise NotImplementedError NotImplementedError I have marked this as EasyToFix because the solving procedure would be rather simple. First of course, it would need to check if the symbol appears only once, which would be easy. It could maybe also check to make sure that it is not in any non-invertible functions while it is at it. It would just need some kind of dictionary of operators/functions and their inverses. It would parse the expression. It starts out with sol = 0. If the expression has multiple args, such as an Add or a Mul, it would subtract/divide everything except for the arg that has the expression from sol and would also remove them from the expression. If the expression has only one arg (such as a function, and Pow would also fit into this case), then it would apply the inverse operator to sol and then apply itself to what remains, possibly duplicating sol for something like a +/- sqrt (really it should be mapping to a list of sols), until it reaches the variable to solve for, at which point it stops and returns the list of solutions. -- 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sympy-issues?hl=en -~----------~----~----~----~------~----~------~--~---
