Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dsolve should not preprocess ODEs #21791

Open
oscarbenjamin opened this issue Jul 27, 2021 · 0 comments
Open

dsolve should not preprocess ODEs #21791

oscarbenjamin opened this issue Jul 27, 2021 · 0 comments

Comments

@oscarbenjamin
Copy link
Contributor

CC @Mohitbalwani26

The ODE below should be easy for dsolve to solve using the nth_algebraic hint. It doesn't work though because dsolve preprocesses the ODE and evaluates all the derivatives so the nth_algebraic solver doesn't get to see the unevaluated derivative form that it knows how to solve. Although classify_ode says nth_algebraic can solve it dsolve will not use the nth_algebraic hint and then an exception is raised in the series solvers. The preprocessing in dsolve should be removed so that nth_algebraic can access the ODE in its original unprocessed form.

In [1]: eq = Derivative(f(x)*g(x), (x, 2))

In [2]: eq
Out[2]: 
  2           
 d            
───(f(x)⋅g(x))
  2           
dx            

In [3]: classify_ode(eq, f(x))
Out[3]: ('nth_algebraic', '2nd_power_series_ordinary', 'nth_algebraic_Integral')

In [4]: dsolve(eq, f(x))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-3a286ce8891f> in <module>
----> 1 dsolve(eq, f(x))

~/current/sympy/sympy/sympy/solvers/ode/ode.py in dsolve(eq, func, hint, simplify, ics, xi, eta, x0, n, **kwargs)
    637             # The key 'hint' stores the hint needed to be solved for.
    638             hint = hints['hint']
--> 639             return _helper_simplify(eq, hint, hints, simplify, ics=ics)
    640 
    641 def _helper_simplify(eq, hint, match, simplify=True, ics=None, **kwargs):

~/current/sympy/sympy/sympy/solvers/ode/ode.py in _helper_simplify(eq, hint, match, simplify, ics, **kwargs)
    668             sols = solvefunc.get_general_solution()
    669         else:
--> 670             sols = solvefunc(eq, func, order, match)
    671         if iterable(sols):
    672             rv = [odesimp(eq, s, func, hint) for s in sols]

~/current/sympy/sympy/sympy/solvers/ode/ode.py in ode_2nd_power_series_ordinary(eq, func, order, match)
   2391     # Finding the recurrence relation in terms of the largest term.
   2392     fargs = req.atoms(AppliedUndef)
-> 2393     maxf = max(fargs, key = lambda x: x.args[0])
   2394     minf = min(fargs, key = lambda x: x.args[0])
   2395     if minf.args[0].is_Symbol:

~/current/sympy/sympy/sympy/core/relational.py in __bool__(self)
    396 
    397     def __bool__(self):
--> 398         raise TypeError("cannot determine truth value of Relational")
    399 
    400     def _eval_as_set(self):

TypeError: cannot determine truth value of Relational

There also seems to be a bug here in the 2nd_power_series_ordinary solver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant