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

PolynomialError when I try to call classify_ode #23425

Closed
satels opened this issue Apr 25, 2022 · 1 comment · Fixed by #23478
Closed

PolynomialError when I try to call classify_ode #23425

satels opened this issue Apr 25, 2022 · 1 comment · Fixed by #23478

Comments

@satels
Copy link
Contributor

satels commented Apr 25, 2022

from sympy import Function, Symbol, classify_ode, Eq, E
x = Symbol('x')
y = Function('y')
eq = Eq(-E**x*y(x).diff().diff() + y(x).diff(), 0)
classify_ode(eq)

THERE IS ERROR

eq = Eq(-E**x*y(x).diff().diff() + y(x).diff(), 0)
eq
Eq(-exp(x)*Derivative(y(x), (x, 2)) + Derivative(y(x), x), 0)

The error:

Traceback (most recent call last):
  File "/home/satels/workenv/krcore/lib/python3.9/site-packages/sympy/polys/polyutils.py", line 211, in _parallel_dict_from_expr_if_gens
    monom[indices[base]] = exp
KeyError: exp(x)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.9/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "/home/satels/workenv/krcore/lib/python3.9/site-packages/sympy/solvers/ode/ode.py", line 1033, in classify_ode
    if solver.matches():
  File "/home/satels/workenv/krcore/lib/python3.9/site-packages/sympy/solvers/ode/single.py", line 289, in matches
    self._matched = self._matches()
  File "/home/satels/workenv/krcore/lib/python3.9/site-packages/sympy/solvers/ode/single.py", line 2092, in _matches
    d = equivalence_hypergeometric(A, B, func)
  File "/home/satels/workenv/krcore/lib/python3.9/site-packages/sympy/solvers/ode/hypergeometric.py", line 116, in equivalence_hypergeometric
    sing_point.append(list(roots(arg, x).keys())[0])
  File "/home/satels/workenv/krcore/lib/python3.9/site-packages/sympy/polys/polyroots.py", line 886, in roots
    F = Poly(f, *gens, **flags)
  File "/home/satels/workenv/krcore/lib/python3.9/site-packages/sympy/polys/polytools.py", line 181, in __new__
    return cls._from_expr(rep, opt)
  File "/home/satels/workenv/krcore/lib/python3.9/site-packages/sympy/polys/polytools.py", line 310, in _from_expr
    rep, opt = _dict_from_expr(rep, opt)
  File "/home/satels/workenv/krcore/lib/python3.9/site-packages/sympy/polys/polyutils.py", line 368, in _dict_from_expr
    rep, gens = _dict_from_expr_if_gens(expr, opt)
  File "/home/satels/workenv/krcore/lib/python3.9/site-packages/sympy/polys/polyutils.py", line 307, in _dict_from_expr_if_gens
    (poly,), gens = _parallel_dict_from_expr_if_gens((expr,), opt)
  File "/home/satels/workenv/krcore/lib/python3.9/site-packages/sympy/polys/polyutils.py", line 216, in _parallel_dict_from_expr_if_gens
    raise PolynomialError("%s contains an element of "
sympy.polys.polyerrors.PolynomialError: exp(2*x) contains an element of the set of generators.
@oscarbenjamin
Copy link
Contributor

Maybe something like this is needed:

diff --git a/sympy/solvers/ode/hypergeometric.py b/sympy/solvers/ode/hypergeometric.py
index b159053048..e0c42482b4 100644
--- a/sympy/solvers/ode/hypergeometric.py
+++ b/sympy/solvers/ode/hypergeometric.py
@@ -50,6 +50,8 @@ def match_2nd_hypergeometric(eq, func):
             n, d = eq.as_numer_denom()
             eq = expand(n)
             r = collect(eq, [func.diff(x, 2), func.diff(x), func]).match(deq)
+            if not all(val.is_polynomial() for val in r.values()):
+                return []
 
     if r and r[a3]!=0:
         A = cancel(r[b3]/r[a3])

I'm not sure exactly what the restrictions are for the 2nd hypergeometric method. I guess the coefficients should be required to be polynomial in the dependent variable.

skirpichev added a commit to skirpichev/diofant that referenced this issue Apr 27, 2022
skirpichev added a commit to skirpichev/diofant that referenced this issue Apr 27, 2022
skirpichev added a commit to skirpichev/diofant that referenced this issue Apr 28, 2022
skirpichev added a commit to skirpichev/diofant that referenced this issue Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants