Status: Accepted
Owner: asmeurer
Labels: Type-Defect Priority-Low

New issue 1996 by asmeurer: Incorrect exception in dsolve()
http://code.google.com/p/sympy/issues/detail?id=1996

from sympy import *
from sympy.abc import x
f = Function('f')
classify_ode(f(x).diff(x)**2, f(x)) # This kind of ODE can't be solved
()
dsolve(f(x).diff(x)**2, f(x)) # We should get NotImplementedError
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy/solvers/ode.py", line 409, in dsolve
    raise NotImplementedError("dsolve: Cannot solve " + str(eq))
NotImplementedError: dsolve: Cannot solve D(f(x), x)**2
classify_ode(f(x).diff(x, x), f(x))
('nth_linear_constant_coeff_homogeneous', 'Liouville', 'Liouville_Integral')
dsolve(f(x).diff(x, x), f(x), hint='separable') # separable is a valid hint, but not for this ODE
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy/solvers/ode.py", line 448, in dsolve
    raise ValueError("ODE " + str(eq) + " does not match hint " + hint)
ValueError: ODE D(f(x), x, x) does not match hint separable
# So we get ValueError
...
dsolve(f(x).diff(x)**2, f(x), 'separable') # So we should get ValueError again, for the same reason
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy/solvers/ode.py", line 409, in dsolve
    raise NotImplementedError("dsolve: Cannot solve " + str(eq))
NotImplementedError: dsolve: Cannot solve D(f(x), x)**2
# Oops.  I guess not.  Bug.

Basically, it isn't checking if there is a hint before raising NotImplementedError, but if there is, it should be raising ValueError, either for non-matching hint, or invalid hint:


dsolve(f(x).diff(x, x), f(x), hint='fdsjf') # fdsjf is not a valid hint
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy/solvers/ode.py", line 446, in dsolve
    raise ValueError("Hint not recognized: " + hint)
ValueError: Hint not recognized: fdsjf
dsolve(f(x).diff(x)**2, f(x), 'fdsjf') # So we should get ValueError again, for the same reason
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy/solvers/ode.py", line 409, in dsolve
    raise NotImplementedError("dsolve: Cannot solve " + str(eq))
NotImplementedError: dsolve: Cannot solve D(f(x), x)**2

It's not terribly important, but it *is* the wrong exception.


--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to sympy-iss...@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