Opened 6 years ago

Closed 6 years ago

#19904 closed defect (fixed)

Crash in SR(QQbar)

Reported by: vbraun Owned by:
Priority: major Milestone: sage-7.0
Component: symbolics Keywords:
Cc: Merged in:
Authors: Ralf Stephan Reviewers: Jeroen Demeyer
Report Upstream: N/A Work issues:
Branch: b974f51 (Commits, GitHub, GitLab) Commit: b974f51b47373bbd9fef81bce1b5603ca70e0908
Dependencies: Stopgaps:

Status badges

Description (last modified by jdemeyer)

QQbar wrapped in SR can lead to Sage crashing:

sage: bool(SR(QQbar(I)) == I)
terminate called after throwing an instance of 'std::runtime_error'
  what():  
------------------------------------------------------------------------
/home/vbraun/Code/sage/local/lib/python2.7/site-packages/sage/ext/interrupt/interrupt.so(+0x3da5)[0x7f06b9187da5]
/home/vbraun/Code/sage/local/lib/python2.7/site-packages/sage/ext/interrupt/interrupt.so(+0x3df7)[0x7f06b9187df7]
/home/vbraun/Code/sage/local/lib/python2.7/site-packages/sage/ext/interrupt/interrupt.so(+0x644c)[0x7f06b918a44c]
/lib64/libpthread.so.0(+0x109f0)[0x7f06c8b0e9f0]
/lib64/libc.so.6(gsignal+0x38)[0x7f06c8068a98]
/lib64/libc.so.6(abort+0x16a)[0x7f06c806a69a]
/home/vbraun/Code/sage/local/lib/libstdc++.so.6(__gnu_cxx::__verbose_terminate_handler()+0x15d)[0x7f06acab2ccd]
/home/vbraun/Code/sage/local/lib/libstdc++.so.6(+0x5dd46)[0x7f06acab0d46]
/home/vbraun/Code/sage/local/lib/libstdc++.so.6(+0x5dd91)[0x7f06acab0d91]
/home/vbraun/Code/sage/local/lib/libstdc++.so.6(+0x5dfa9)[0x7f06acab0fa9]
/home/vbraun/Code/sage/local/lib/libpynac.so.0(py_error(char const*)+0x70)[0x7f069376ede0]
/home/vbraun/Code/sage/local/lib/libpynac.so.0(GiNaC::numeric::numeric(_object*, bool)+0x1b8)[0x7f069376f9e8]
/home/vbraun/Code/sage/local/lib/libpynac.so.0(GiNaC::numeric::add(GiNaC::numeric const&) const+0x1fa)[0x7f0693776c6a]
/home/vbraun/Code/sage/local/lib/libpynac.so.0(GiNaC::operator+(GiNaC::numeric const&, GiNaC::numeric const&)+0x9)[0x7f069377a3a9]
/home/vbraun/Code/sage/local/lib/libpynac.so.0(GiNaC::numeric::add_dyn(GiNaC::numeric const&) const+0x39)[0x7f0693770889]
/home/vbraun/Code/sage/local/lib/libpynac.so.0(GiNaC::expairseq::combine_overall_coeff(GiNaC::ex const&)+0x1a)[0x7f06936d163a]
/home/vbraun/Code/sage/local/lib/libpynac.so.0(GiNaC::expairseq::construct_from_2_ex(GiNaC::ex const&, GiNaC::ex const&)+0x375)[0x7f06936d6515]
/home/vbraun/Code/sage/local/lib/libpynac.so.0(GiNaC::add::add(GiNaC::ex const&, GiNaC::ex const&)+0x63)[0x7f06936a5a73]
/home/vbraun/Code/sage/local/lib/libpynac.so.0(GiNaC::operator-(GiNaC::ex const&, GiNaC::ex const&)+0x5f)[0x7f069377b0af]
/home/vbraun/Code/sage/local/lib/libpynac.so.0(GiNaC::relational::decide() const+0x46)[0x7f069378b886]
/home/vbraun/Code/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.so(+0x9ec48)[0x7f0693387c48]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyObject_IsTrue+0x37)[0x7f06c8dbaa57]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(+0x54e4e)[0x7f06c8d6fe4e]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(+0xbcb63)[0x7f06c8dd7b63]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f06c8d6dc43]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x3b2e)[0x7f06c8e2228e]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x830)[0x7f06c8e255a0]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalCode+0x19)[0x7f06c8e256c9]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x58de)[0x7f06c8e2403e]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x830)[0x7f06c8e255a0]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5936)[0x7f06c8e24096]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x830)[0x7f06c8e255a0]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5936)[0x7f06c8e24096]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x830)[0x7f06c8e255a0]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5936)[0x7f06c8e24096]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x830)[0x7f06c8e255a0]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5936)[0x7f06c8e24096]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x830)[0x7f06c8e255a0]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5936)[0x7f06c8e24096]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x830)[0x7f06c8e255a0]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5936)[0x7f06c8e24096]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x830)[0x7f06c8e255a0]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyEval_EvalCode+0x19)[0x7f06c8e256c9]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyRun_FileExFlags+0x8a)[0x7f06c8e4949a]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(PyRun_SimpleFileExFlags+0xd7)[0x7f06c8e4aa27]
/home/vbraun/Code/sage/local/lib/libpython2.7.so.1.0(Py_Main+0xc25)[0x7f06c8e60c25]
/lib64/libc.so.6(__libc_start_main+0xf0)[0x7f06c8054580]
python(_start+0x29)[0x400769]

Change History (10)

comment:1 Changed 6 years ago by vbraun

This is obviously so because QQbar and NumberField don't interoperate

sage: K.<a> = NumberField(x^2+1, embedding=CC.gen())
sage: QQbar.gen() + a
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-22-662328c835b1> in <module>()
----> 1 QQbar.gen() + a

/home/vbraun/Code/sage/src/sage/structure/element.pyx in sage.structure.element.RingElement.__add__ (/home/vbraun/Code/sage/src/build/cythonized/sage/structure/element.c:15852)()
   1649         elif PyInt_CheckExact(left):
   1650             return (<RingElement>right)._add_long(PyInt_AS_LONG(left))
-> 1651         return coercion_model.bin_op(left, right, add)
   1652 
   1653     cdef RingElement _add_long(self, long n):

/home/vbraun/Code/sage/src/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (/home/vbraun/Code/sage/src/build/cythonized/sage/structure/coerce.c:9736)()
   1067         # We should really include the underlying error.
   1068         # This causes so much headache.
-> 1069         raise TypeError(arith_error_message(x,y,op))
   1070 
   1071     cpdef canonical_coercion(self, x, y):

TypeError: unsupported operand parent(s) for '+': 'Algebraic Field' and 'Number Field in a with defining polynomial x^2 + 1'

Still, pynac should just raise that exception and not crash.

comment:2 Changed 6 years ago by vdelecroix

You can have better cooperation with

sage: K1 = NumberField(x^2+1, 'a', embedding=CC.gen())
sage: K2 = NumberField(x^2+1, 'a', embedding=QQbar.gen())
sage: K2.gen() + QQbar.gen()
2*I

I do not think that a declared embedding to CC should be compatible with QQbar operations. Or all embeddings should implictely be refined to have values in AA or QQbar. Currently

sage: K1.coerce_embedding()
Generic morphism:
  From: Number Field in a with defining polynomial x^2 + 1
  To:   Complex Lazy Field
  Defn: a -> 1*I
sage: K2.coerce_embedding()
Generic morphism:
  From: Number Field in a with defining polynomial x^2 + 1
  To:   Algebraic Field
  Defn: a -> 1*I

comment:3 Changed 6 years ago by rws

  • Branch set to u/rws/segfault_in_sr_qqbar_

comment:4 Changed 6 years ago by rws

  • Authors set to Ralf Stephan
  • Commit set to 994a8d5c95863fc9f231b870e91cfc12323cad2a
  • Status changed from new to needs_review

It's not Pynac that crashes. The runtime error is just not caught. When fixed it will give:

/home/ralf/sage/src/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:9736)()
   1067         # We should really include the underlying error.
   1068         # This causes so much headache.
-> 1069         raise TypeError(arith_error_message(x,y,op))
   1070
   1071     cpdef canonical_coercion(self, x, y):

TypeError: unsupported operand parent(s) for '+': 'Algebraic Field' and 'Number Field in I with defining polynomial x^2 + 1'

New commits:

994a8d519904: catch exceptions from GiNaC::decide_relational()

comment:5 Changed 6 years ago by jdemeyer

If you add a doctest, this is good for me.

comment:6 Changed 6 years ago by jdemeyer

  • Reviewers set to Jeroen Demeyer
  • Status changed from needs_review to needs_work

comment:7 Changed 6 years ago by git

  • Commit changed from 994a8d5c95863fc9f231b870e91cfc12323cad2a to b974f51b47373bbd9fef81bce1b5603ca70e0908

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

b974f5119904: doctest

comment:8 Changed 6 years ago by rws

  • Status changed from needs_work to positive_review

comment:9 Changed 6 years ago by jdemeyer

  • Description modified (diff)
  • Summary changed from Segfault in SR(QQbar) to Crash in SR(QQbar)

comment:10 Changed 6 years ago by vbraun

  • Branch changed from u/rws/segfault_in_sr_qqbar_ to b974f51b47373bbd9fef81bce1b5603ca70e0908
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.