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

TypeError: unorderable types: PolyElement() < mpz() from factor_list #11775

Open
asmeurer opened this Issue Oct 26, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@asmeurer
Copy link
Member

asmeurer commented Oct 26, 2016

In [1]: factor_list(y**4 + x*y**3 + y**2 + x*y, y)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-4bdc2a19b874> in <module>()
----> 1 factor_list(y**4 + x*y**3 + y**2 + x*y, y)

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/polys/polytools.py in factor_list(f, *gens, **args)
   5987
   5988     """
-> 5989     return _generic_factor_list(f, gens, args, method='factor')
   5990
   5991

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/polys/polytools.py in _generic_factor_list(expr, gens, args, method)
   5732                     factors[i] = (f, k)
   5733
-> 5734         fp = _sorted_factors(fp, method)
   5735         fq = _sorted_factors(fq, method)
   5736

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/polys/polytools.py in _sorted_factors(factors, method)
   5630             return (len(rep), exp, rep)
   5631
-> 5632     return sorted(factors, key=key)
   5633
   5634

TypeError: unorderable types: PolyElement() < mpz()

Note that you need to use Python 3 to reproduce this error.

@asmeurer asmeurer added the polys label Oct 26, 2016

@asmeurer

This comment has been minimized.

Copy link
Member

asmeurer commented Oct 26, 2016

The problem is that _sorted_factors doesn't handle non-numeric coefficients. Is there a key function in the polys to sort PolyElements?

@asmeurer

This comment has been minimized.

Copy link
Member

asmeurer commented Oct 26, 2016

PolyElement has a sort_key() method. But how should it be applied in _sorted_factors?

@jksuom

This comment has been minimized.

Copy link
Member

jksuom commented Oct 26, 2016

One of the factors has integer coefficients while the others have polynomial coefficients:

(Pdb) p factors
[(Poly(y, y, domain='ZZ'), 1), (Poly(y + x, y, domain='ZZ[x]'), 1), (Poly(y**2 + 1, y, domain='ZZ[x]'), 1)]

A possible workaround is forcing all coefficients to be polynomials:

Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy import *
>>> from sympy.abc import x, y
>>> factor_list(y**4 + x*y**3 + y**2 + x*y, y, domain='ZZ[x]')
(1, [(y, 1), (x + y, 1), (y**2 + 1, 1)])

It seems that domain should be internally added to all factors before sorting. Otherwise, it may be hard to prepare for different types of coefficients.

skirpichev added a commit to skirpichev/diofant that referenced this issue Sep 18, 2018

skirpichev added a commit to skirpichev/diofant that referenced this issue Sep 19, 2018

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