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

conversions of constant polynomials #10147

Closed
mezzarobba opened this issue Oct 20, 2010 · 18 comments
Closed

conversions of constant polynomials #10147

mezzarobba opened this issue Oct 20, 2010 · 18 comments

Comments

@mezzarobba
Copy link
Member

Many conversions of constant polynomials fail

sage: CC(QQ['x']['y'](2/3))
Traceback (most recent call last):
...
TypeError: unable to coerce to a ComplexNumber:
<class 'sage.rings.polynomial.polynomial_element.Polynomial_generic_dense'>

As a consequence, some root computations are not available

sage: R.<x> = QQ['y'][]
sage: (-x+1).roots(ring=CC)
[(1.00000000000000, 1)]
sage: (-1/2*x+1).roots(ring=CC)
Traceback (most recent call last):
...
TypeError: unable to coerce to a ComplexNumber:
<class 'sage.rings.polynomial.polynomial_element.Polynomial_generic_dense'>

(this used to crash on older version of SageMath, see below).


Original report on previous version of sage

p.roots(ring=CC) where p is an element QQ['y']['x'] whose coefficient do not depend on y leads to several different errors depending on the value of p. I guess there are in fact several distinct issues. The final crash might be related to #9826.

~$ sage
----------------------------------------------------------------------
| Sage Version 4.5.3, Release Date: 2010-09-04                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: R.<x> = QQ['y'][]
sage: (-x+1).roots(ring=CC)
[(1.00000000000000, 1)]
sage: (-1/2*x+1).roots(ring=CC)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (19469, 0))

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/marc/<ipython console> in <module>()

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.roots (sage/rings/polynomial/polynomial_element.c:31226)()

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.change_ring (sage/rings/polynomial/polynomial_element.c:16456)()

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:6407)()

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3108)()

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3010)()

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_ring.pyc in _element_constructor_(self, x, check, is_gen, construct, **kwds)
    311                 x = x.Polrev()
    312 
--> 313         return C(self, x, check, is_gen, construct=construct, **kwds)
    314 
    315     def is_integral_domain(self, proof = True):

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_real_mpfr_dense.so in sage.rings.polynomial.polynomial_real_mpfr_dense.PolynomialRealDense.__init__ (sage/rings/polynomial/polynomial_real_mpfr_dense.c:3609)()

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:6407)()

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3108)()

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3010)()

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/rings/real_mpfr.so in sage.rings.real_mpfr.RealField_class._element_constructor_ (sage/rings/real_mpfr.c:5058)()

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/rings/real_mpfr.so in sage.rings.real_mpfr.RealNumber._set (sage/rings/real_mpfr.c:8767)()

TypeError: Unable to convert x (='-1/2') to real number.
sage: (-1/2*x+1/2).roots()
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)

/home/marc/<ipython console> in <module>()

/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.roots (sage/rings/polynomial/polynomial_element.c:31591)()

NotImplementedError: root finding for this polynomial not implemented
sage: (-1/2*x+1/2).roots(ring=CC)
*** glibc detected *** python: munmap_chunk(): invalid pointer: 0x0000000001208958 ***
======= Backtrace: =========
/lib/libc.so.6[0x3c38271ad6]
/home/marc/opt/sage-4.5.3/local/lib/libmpfr.so.1(mpfr_clear+0x45)[0x7fc911f80a45]
/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_real_mpfr_dense.so(+0x7867)[0x7fc90a74d867]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(+0xa241c)[0x7fc91e85841c]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyObject_Call+0x53)[0x7fc91e7fce13]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalFrameEx+0x3af3)[0x7fc91e89f973]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalCodeEx+0x8cd)[0x7fc91e8a2d1d]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(+0x730df)[0x7fc91e8290df]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyObject_Call+0x53)[0x7fc91e7fce13]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(+0x5819f)[0x7fc91e80e19f]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyObject_Call+0x53)[0x7fc91e7fce13]
/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/structure/coerce_maps.so(+0x12724)[0x7fc910609724]
/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/structure/parent.so(+0x25ec2)[0x7fc9174a2ec2]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyObject_Call+0x53)[0x7fc91e7fce13]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(+0xaba8c)[0x7fc91e861a8c]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyObject_Call+0x53)[0x7fc91e7fce13]
/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so(+0xd3c2)[0x7fc90bc873c2]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyObject_Call+0x53)[0x7fc91e7fce13]
/home/marc/opt/sage-4.5.3/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so(+0xd191c)[0x7fc90bd4b91c]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalFrameEx+0x5a8e)[0x7fc91e8a190e]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalCodeEx+0x8cd)[0x7fc91e8a2d1d]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalCode+0x32)[0x7fc91e8a2df2]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalFrameEx+0x6244)[0x7fc91e8a20c4]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalCodeEx+0x8cd)[0x7fc91e8a2d1d]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalFrameEx+0x5235)[0x7fc91e8a10b5]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalCodeEx+0x8cd)[0x7fc91e8a2d1d]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalFrameEx+0x5235)[0x7fc91e8a10b5]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalFrameEx+0x5ab2)[0x7fc91e8a1932]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalCodeEx+0x8cd)[0x7fc91e8a2d1d]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalFrameEx+0x5235)[0x7fc91e8a10b5]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalCodeEx+0x8cd)[0x7fc91e8a2d1d]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalFrameEx+0x5235)[0x7fc91e8a10b5]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalCodeEx+0x8cd)[0x7fc91e8a2d1d]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalFrameEx+0x5235)[0x7fc91e8a10b5]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalCodeEx+0x8cd)[0x7fc91e8a2d1d]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyEval_EvalCode+0x32)[0x7fc91e8a2df2]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyRun_FileExFlags+0xb0)[0x7fc91e8c2c90]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(PyRun_SimpleFileExFlags+0xdc)[0x7fc91e8c2e5c]
/home/marc/opt/sage-4.5.3/local/lib/libpython2.6.so.1.0(Py_Main+0xb36)[0x7fc91e8d0186]
/lib/libc.so.6(__libc_start_main+0xfd)[0x3c3821ec4d]
python[0x400699]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:0a 1787644                            /home/marc/opt/sage-4.5.3/local/bin/python
00600000-00601000 rw-p 00000000 08:0a 1787644                            /home/marc/opt/sage-4.5.3/local/bin/python
00cb1000-05306000 rw-p 00000000 00:00 0                                  [heap]
32b2c00000-32b2c16000 r-xp 00000000 08:06 40741                          /lib/libgcc_s.so.1
32b2c16000-32b2e15000 ---p 00016000 08:06 40741                          /lib/libgcc_s.so.1
32b2e15000-32b2e16000 rw-p 00015000 08:06 40741                          /lib/libgcc_s.so.1
3c37e00000-3c37e1e000 r-xp 00000000 08:06 40724                          /lib/ld-2.11.2.so
3c3801d000-3c3801e000 r--p 0001d000 08:06 40724                          /lib/ld-2.11.2.so
3c3801e000-3c3801f000 rw-p 0001e000 08:06 40724                          /lib/ld-2.11.2.so
3c3801f000-3c38020000 rw-p 00000000 00:00 0 
3c38200000-3c38358000 r-xp 00000000 08:06 40737                          /lib/libc-2.11.2.so
3c38358000-3c38557000 ---p 00158000 08:06 40737                          /lib/libc-2.11.2.so
3c38557000-3c3855b000 r--p 00157000 08:06 40737                          /lib/libc-2.11.2.so
3c3855b000-3c3855c000 rw-p 0015b000 08:06 40737                          /lib/libc-2.11.2.so
3c3855c000-3c38561000 rw-p 00000000 00:00 0 
3c38600000-3c38680000 r-xp 00000000 08:06 40787                          /lib/libm-2.11.2.so
3c38680000-3c38880000 ---p 00080000 08:06 40787                          /lib/libm-2.11.2.so
3c38880000-3c38881000 r--p 00080000 08:06 40787                          /lib/libm-2.11.2.so
3c38881000-3c38882000 rw-p 00081000 08:06 40787                          /lib/libm-2.11.2.so
3c38a00000-3c38a02000 r-xp 00000000 08:06 40738                          /lib/libdl-2.11.2.so
3c38a02000-3c38c02000 ---p 00002000 08:06 40738                          /lib/libdl-2.11.2.so
3c38c02000-3c38c03000 r--p 00002000 08:06 40738                          /lib/libdl-2.11.2.so
3c38c03000-3c38c04000 rw-p 00003000 08:06 40738                          /lib/libdl-2.11.2.so
3c38e00000-3c38e17000 r-xp 00000000 08:06 40766                          /lib/libpthread-2.11.2.so
3c38e17000-3c39016000 ---p 00017000 08:06 40766                          /lib/libpthread-2.11.2.so
3c39016000-3c39017000 r--p 00016000 08:06 40766                          /lib/libpthread-2.11.2.so
3c39017000-3c39018000 rw-p 00017000 08:06 40766                          /lib/libpthread-2.11.2.so
3c39018000-3c3901c000 rw-p 00000000 00:00 0 
3c4ba00000-3c4ba08000 r-xp 00000000 08:06 40917                          /lib/libcrypt-2.11.2.so
3c4ba08000-3c4bc07000 ---p 00008000 08:06 40917                          /lib/libcrypt-2.11.2.so
3c4bc07000-3c4bc08000 r--p 00007000 08:06 40917                          /lib/libcrypt-2.11.2.so
3c4bc08000-3c4bc09000 rw-p 00008000 08:06 40917                          /lib/libcrypt-2.11.2.so

CC: @jasongrout

Component: algebra

Author: Vincent Delecroix

Branch/Commit: 6822948

Reviewer: Matthias Koeppe

Issue created by migration from https://trac.sagemath.org/ticket/10147

@mezzarobba mezzarobba added this to the sage-5.11 milestone Oct 20, 2010
@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@mezzarobba
Copy link
Member Author

comment:6

No longer crashes; the errors in the cases that are not implemented make sense; I doubt this is worth adding tests.

@mezzarobba mezzarobba removed this from the sage-6.4 milestone Mar 9, 2021
@videlec
Copy link
Contributor

videlec commented Mar 14, 2021

comment:7

In sage-9.3.beta7 the example fails because of

sage: RR(QQ['y'](-1/2)) 
Traceback (most recent call last):
...
TypeError: unable to convert '-1/2' to a real number

which is worth fixing.

@videlec
Copy link
Contributor

videlec commented Mar 14, 2021

comment:8

As a matter of comparison, it works in QQ

sage: R.<x> = QQ['y'][]
sage: (-1/2*x+1).roots(ring=QQ)
[(2, 1)]

This is because the conversion works

sage: QQ(QQ['y'](1/2))
1/2

This is explained by the fact that the conversion method _rational_ is implemented on polynomial

sage: QQ['x'](1/2)._rational_()
1/2

It is worth adding the corresponding conversion methods for floating point numbers

  • _mpfr_ for RealField
  • _real_mpfi_ for RealIntervalField
    Though, complex numbers do not have a conversion method (set in the constructor via self._populate_coercion_lists_(convert_method_name='XXX')).

@videlec videlec added this to the sage-9.4 milestone Mar 14, 2021
@videlec
Copy link
Contributor

videlec commented Mar 14, 2021

Author: Vincent Delecroix

@videlec
Copy link
Contributor

videlec commented Mar 14, 2021

Branch: u/vdelecroix/10147

@videlec
Copy link
Contributor

videlec commented Mar 14, 2021

New commits:

ee49837add convert method for ComplexField
4c7a3c3more scalar conversions for polynomials

@videlec
Copy link
Contributor

videlec commented Mar 14, 2021

Commit: 4c7a3c3

@videlec

This comment has been minimized.

@videlec videlec changed the title Inconsistent behaviour of p.roots(ring=CC) for p(x) in QQ['y']['x'] (incl. crashing) conversions of constant polynomials Mar 14, 2021
@videlec

This comment has been minimized.

@mkoeppe
Copy link
Contributor

mkoeppe commented Mar 14, 2021

comment:13

Patchbot shows doctest errors

@videlec
Copy link
Contributor

videlec commented Mar 17, 2021

comment:14

Replying to @mkoeppe:

Patchbot shows doctest errors

which one?

@videlec
Copy link
Contributor

videlec commented Mar 17, 2021

comment:16

thx

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 17, 2021

Changed commit from 4c7a3c3 to 6822948

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 17, 2021

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

6822948fix doctests

@mkoeppe
Copy link
Contributor

mkoeppe commented Mar 18, 2021

Reviewer: Matthias Koeppe

@mkoeppe
Copy link
Contributor

mkoeppe commented Mar 18, 2021

comment:19

LGTM

@vbraun
Copy link
Member

vbraun commented Mar 20, 2021

Changed branch from u/vdelecroix/10147 to 6822948

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

No branches or pull requests

6 participants