Opened 4 years ago

Closed 4 years ago

# sympy misbehavoir

Reported by: Owned by: vdelecroix major sage-8.2 packages: standard jdemeyer, fbissey Vincent Delecroix Ralf Stephan Fixed upstream, but not in a stable release. 4238d34 4238d34282fb80c302c57bacfec0a2c17bfe6e8a

Sympy polyomials with Sage real number coefficients look very broken

```sage: import sympy, sympy.polys
sage: x = sympy.Symbol('x')
sage: p = sympy.polys.Poly(x**2 - 2.0)
sage: p
<repr(<sympy.polys.polytools.Poly at 0x7f92ca50ef18>) failed: TypeError: int() argument must be a string or a number, not 'NoneType'>
sage: p.coeffs()
TypeError                                 Traceback (most recent call last)
<ipython-input-24-7e7e3b79f346> in <module>()
----> 1 p.coeffs()

/opt/sage/local/lib/python2.7/site-packages/sympy/polys/polytools.pyc in coeffs(f, order)
795
796         """
--> 797         return [f.rep.dom.to_sympy(c) for c in f.rep.coeffs(order=order)]
798
799     def monoms(f, order=None):

/opt/sage/local/lib/python2.7/site-packages/sympy/polys/domains/realfield.pyc in to_sympy(self, element)
64     def to_sympy(self, element):
65         """Convert ``element`` to SymPy number. """
---> 66         return Float(element, self.dps)
67
68     def from_sympy(self, expr):

/opt/sage/local/lib/python2.7/site-packages/sympy/core/numbers.pyc in __new__(cls, num, dps, prec, precision)
1053                 _mpf_ = mpf_norm(_mpf_, precision)
1054         else:
-> 1055             _mpf_ = mpmath.mpf(num, prec=prec)._mpf_
1056
1057         # special cases

/opt/sage/src/sage/libs/mpmath/ext_main.pyx in sage.libs.mpmath.ext_main.mpf.__init__ (build/cythonized/sage/libs/mpmath/ext_main.c:23448)()
1886         opts = global_opts
1887         if kwargs:
-> 1888             if 'prec' in kwargs: opts.prec = int(kwargs['prec'])
1889             if 'dps'  in kwargs: opts.prec = libmp.dps_to_prec(int(kwargs['dps']))
1890             if 'rounding' in kwargs: opts.rounding = rndmode_from_python(kwargs['rounding'])

TypeError: int() argument must be a string or a number, not 'NoneType'
```

We backport a patch in sympy development branch. This problem was originally found from digging around #24378. Upstream fix is at https://github.com/sympy/sympy/pull/13276

### comment:1 Changed 4 years ago by vdelecroix

• Description modified (diff)
• Summary changed from sympy misbehavoir with gmpy2 installed to sympy misbehavoir (with gmpy2 installed)

### comment:2 Changed 4 years ago by vdelecroix

Updating sympy to the development version makes it working

```sage: import sympy, sympy.polys
sage: sympy.__version__
'1.1.2.dev'
sage: x = sympy.Symbol('x')
sage: p = sympy.polys.Poly(x**2 - 2.0)
sage: p
Poly(1.0*x**2 - 2.0, x, domain='RR')
sage: p.coeffs()
[1.00000000000000, -2.00000000000000]
sage: map(type,p.coeffs())
[<class 'sympy.core.numbers.Float'>, <class 'sympy.core.numbers.Float'>]
```

### comment:3 Changed 4 years ago by vdelecroix

• Authors set to Vincent Delecroix
• Branch set to u/vdelecroix/24380
• Report Upstream changed from Not yet reported upstream; Will do shortly. to Fixed upstream, but not in a stable release.
• Status changed from new to needs_review

New commits:

 ​3e423f0 `24380: sympy ackport in core/numbers.py`

### comment:4 Changed 4 years ago by git

• Commit changed from 3e423f02882555ea84ad8100201caf203c524922 to 459c93aef0b14caa722eff807238dbf9e77a16d6

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

 ​459c93a `24380: sympy backport in core/numbers.py`

### comment:5 Changed 4 years ago by vdelecroix

• Description modified (diff)
• Summary changed from sympy misbehavoir (with gmpy2 installed) to sympy misbehavoir

### comment:6 Changed 4 years ago by git

• Commit changed from 459c93aef0b14caa722eff807238dbf9e77a16d6 to be1417d0a5f8169c4c0cb3889864deeb565d9250

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

 ​be1417d `24380: sympy backport in core/numbers.py`

### comment:8 Changed 4 years ago by git

• Commit changed from be1417d0a5f8169c4c0cb3889864deeb565d9250 to 4238d34282fb80c302c57bacfec0a2c17bfe6e8a

Branch pushed to git repo; I updated commit sha1. New commits:

 ​4238d34 `24380: bump sympy package version`

### comment:9 Changed 4 years ago by rws

• Reviewers set to Ralf Stephan
• Status changed from needs_review to positive_review

LGTM.