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

Poly thinks sqrt(2) coefficient makes a polynomial multivariate #15412

Open
oscarbenjamin opened this issue Oct 22, 2018 · 2 comments
Open

Poly thinks sqrt(2) coefficient makes a polynomial multivariate #15412

oscarbenjamin opened this issue Oct 22, 2018 · 2 comments
Labels

Comments

@oscarbenjamin
Copy link
Contributor

I found this while looking at #15408.

The shorthand Poly(expr) for Poly(expr, x) should guess the polynomial variate from the expression expr. However it fails if the polynomial has a coefficient like sqrt(2):

In [6]: roots(sqrt(2)*x**3 + x, x)
Out[6]:3/4        4 ___        ⎫
⎪      -2   ⅈ      ╲╱ 2 ⋅√2ⅈ   ⎪
⎨0: 1, ────────: 1, ──────────: 1⎬
⎪         2             2        ⎪
⎩                                ⎭

In [7]: roots(sqrt(2)*x**3 + x)
---------------------------------------------------------------------------
PolynomialError                           Traceback (most recent call last)
<ipython-input-7-df234384a5fa> in <module>()
----> 1 roots(sqrt(2)*x**3 + x)

/space/enojb/current/sympy/sympy/sympy/polys/polyroots.py in roots(f, *gens, **flags)
    906 
    907         if f.is_multivariate:
--> 908             raise PolynomialError('multivariate polynomials are not supported')
    909 
    910     def _update_dict(result, root, k):

PolynomialError: multivariate polynomials are not supported

In [9]: roots(Poly(sqrt(2)*x**3 + x, x))
Out[9]:3/4        4 ___        ⎫
⎪      -2   ⅈ      ╲╱ 2 ⋅√2ⅈ   ⎪
⎨0: 1, ────────: 1, ──────────: 1⎬
⎪         2             2        ⎪
⎩                                ⎭

In [14]: roots(Poly(sqrt(2)*x**3 + x))
---------------------------------------------------------------------------
PolynomialError                           Traceback (most recent call last)
<ipython-input-14-8f8a5579b962> in <module>()
----> 1 roots(Poly(sqrt(2)*x**3 + x))

/space/enojb/current/sympy/sympy/sympy/polys/polyroots.py in roots(f, *gens, **flags)
    906 
    907         if f.is_multivariate:
--> 908             raise PolynomialError('multivariate polynomials are not supported')
    909 
    910     def _update_dict(result, root, k):

PolynomialError: multivariate polynomials are not supported
@asmeurer
Copy link
Member

This is sort of expected behavior of Poly at the moment. The extension flag defaults to False. Maybe it would be better to use the EX domain instead of treating sqrt(2) as a generator, I don't know. For now, it's best practice to pass the variables as the second argument if you know what they are.

@oscarbenjamin
Copy link
Contributor Author

Okay so shall I close this?

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

No branches or pull requests

2 participants