Bug#1052596: python3-sympy: sympy.Poly() fails with: GeneratorsNeeded: Cannot initialize from 'dict' without generators
Kingsley G. Morse Jr.
kingsley at loaner.com
Mon Sep 25 03:49:29 BST 2023
Package: python3-sympy
Version: 1.12-6
Severity: normal
Thank you very mcuh for maintaining Debian Linux's
"python3-sympy" package.
It's interesting and sophisticated.
Please allow me to draw your attention a possible
bug.
I can elicit it with just 2 lines of code.
Here is how:
$ ipython3
In [1]: from sympy import Poly
In [2]: Poly('((a - b) - (((a - b) + (c - d) + (e - f))/3)) + ((c - d) - (((a - b) + (c - d) + (e - f))/3)) + (e - f) - ((a - b) + (c - d) + (e - f))/3')
sympy.Poly() complains with
---------------------------------------------------------------------------
GeneratorsNeeded Traceback (most recent call last)
Cell In [2], line 1
----> 1 Poly('((a - b) - (((a - b) + (c - d) + (e - f))/3)) + ((c - d) - (((a - b) + (c - d) + (e - f))/3)) + (e - f) - ((a - b) + (c - d) + (e - f))/3')
File /usr/lib/python3/dist-packages/sympy/polys/polytools.py:182, in Poly.__new__(cls, rep, *gens, **args)
180 return cls._from_poly(rep, opt)
181 else:
--> 182 return cls._from_expr(rep, opt)
File /usr/lib/python3/dist-packages/sympy/polys/polytools.py:312, in Poly._from_expr(cls, rep, opt)
310 """Construct a polynomial from an expression. """
311 rep, opt = _dict_from_expr(rep, opt)
--> 312 return cls._from_dict(rep, opt)
File /usr/lib/python3/dist-packages/sympy/polys/polytools.py:249, in Poly._from_dict(cls, rep, opt)
246 gens = opt.gens
248 if not gens:
--> 249 raise GeneratorsNeeded(
250 "Cannot initialize from 'dict' without generators")
252 level = len(gens) - 1
253 domain = opt.domain
GeneratorsNeeded: Cannot initialize from 'dict' without generators
I expected it to work.
Especially because simply deleting the trailing "/3" from the input does, like this...
In [3]: Poly('((a - b) - (((a - b) + (c - d) + (e - f))/3)) + ((c - d) - (((a - b) + (c - d) + (e - f))/3)) + (e - f) - ((a - b) + (c - d) + (e - f))')
Out[3]: Poly(-2/3*a + 2/3*b - 2/3*c + 2/3*d - 2/3*e + 2/3*f, a, b, c, d, e, f, domain='QQ')
I suppose an approximate workaround is to replace the trailing
.../3
with a leading
0.333*...
like this...
In [4]: Poly('((a - b) - (((a - b) + (c - d) + (e - f))/3)) + ((c - d) - (((a - b) + (c - d) + (e - f))/3)) + (e - f) - 0.333*((a - b) +
...: (c - d) + (e - f))')
Out[4]: Poly(0.000333333333333297*a - 0.000333333333333297*b + 0.000333333333333297*c - 0.000333333333333297*d + 0.000333333333333297*e - 0.000333333333333297*f, a, b, c, d, e, f, domain='RR')
I also noticed that replacing the trailing "/3" with division by 1, 2, 4, 5 and 6 worked.
Thanks again for maintaining Debian's python3-sympy package.
Kind regards,
Kingsley
-- System Information:
Debian Release: bullseye/sid
APT prefers unstable-debug
APT policy: (500, 'unstable-debug'), (500, 'unstable')
merged-usr: no
Architecture: i386 (i686)
Kernel: Linux 4.4.0-1-686-pae (SMP w/2 CPU threads)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /bin/bash
Init: systemd (via /run/systemd/system)
Versions of packages python3-sympy depends on:
ii python3 3.11.1-3
ii python3-mpmath 1.2.1-1
Versions of packages python3-sympy recommends:
ii isympy-common 1.7.1-2
ii python3-numpy 1:1.24.2-1
ii python3-pil 9.4.0-1.1+b1
Versions of packages python3-sympy suggests:
pn dvipng <none>
pn python-sympy-doc <none>
pn texlive-fonts-extra <none>
-- no debconf information
More information about the debian-science-maintainers
mailing list