SR is special in that it wraps various other rings:

sage: wrapped_qqbar = SR(QQbar(I))
sage: wrapped_qqbar.parent()
Symbolic Ring
sage: wrapped_qqbar.pyobject()
1*I
sage: wrapped_qqbar.pyobject().parent()
Algebraic Field

You don't gain anything from wrapping stuff in SR; ideally you can avoid it 
in your code.

I opened http://trac.sagemath.org/ticket/19904 with a better testcase for 
the segfault 

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]





On Sunday, January 17, 2016 at 5:39:43 PM UTC, Emmanuel Charpentier wrote:
>
> (Note : Question also asked on ask.sagemath.org, but crossposted because 
> I found a way to CRASH sage...).
> I'm trying to understand coercions, and I'm hitting (repeatedly) something 
> that I do not understand.
>
> Let's try to find thge roots of a polynom. We can try equation solving (of 
> a quartic, no less) :
>
> sage:  w = x^4 - (1+3*i)*x^3 - (2-4*i)*x^2 + (6-2*i)*x - 4 - 4*i
> sage: S1=[t.rhs() for t in solve(w,x)];S1
> [-1/2*sqrt(2*I) + 3/2*I - 1/2, 1/2*sqrt(2*I) + 3/2*I - 1/2, -I + 1, I + 1]
> sage: bool(sqrt(2*I)==1+I)
> True
>
> Or we can try the roots of a polynomial :
>
> sage: S2=[SR(t[0]) for t in w.roots(ring=QQbar)];S2
> [-1 + 1*I, 2*I, 1 - 1*I, 1 + 1*I]
> sage: bool(sqrt(2*I)==1+I)
> True
> sage: S1R=[t.subs({sqrt(2*I):1+I}) for t in S1];S1R
> [I - 1, 2*I, -I + 1, I + 1]
>
> So far, so good. I'm convinced that these two solution lists are one and 
> the same. But I can't find a way to convince Sage:
>
> sage: map(lambda t,u:t-u, S1R, S2)
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> <ipython-input-6-be2e4183b522> in <module>()
> ----> 1 map(lambda t,u:t-u, S1R, S2)
>
> <ipython-input-6-be2e4183b522> in <lambda>(t, u)
> ----> 1 map(lambda t,u:t-u, S1R, S2)
>
> /usr/local/sage-7.0/src/sage/structure/element.pyx in 
> sage.structure.element.RingElement.__sub__ 
> (/usr/local/sage-7.0/src/build/cythonized/sage/structure/element.c:15995)()
>    1665         cdef long n
>    1666         if have_same_parent_c(left, right):
> -> 1667             return 
> (<ModuleElement>left)._sub_(<ModuleElement>right)
>    1668         if PyInt_CheckExact(right):
>    1669             n = PyInt_AS_LONG(right)
>
> /usr/local/sage-7.0/src/sage/symbolic/expression.pyx in 
> sage.symbolic.expression.Expression._sub_ 
> (/usr/local/sage-7.0/src/build/cythonized/sage/symbolic/expression.cpp:20844)()
>    2950                            relational_operator(_right._gobj))
>    2951         else:
> -> 2952             x = gsub(left._gobj, _right._gobj)
>    2953         return new_Expression_from_GEx(left._parent, x)
>    2954 
>
> /usr/local/sage-7.0/src/sage/structure/element.pyx in 
> sage.structure.element.RingElement.__add__ 
> (/usr/local/sage-7.0/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):
>
> /usr/local/sage-7.0/src/sage/structure/coerce.pyx in 
> sage.structure.coerce.CoercionModel_cache_maps.bin_op 
> (/usr/local/sage-7.0/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 '+': 'Number Field in I with 
> defining polynomial x^2 + 1' and 'Algebraic Field'
>
> I do not understand this error : both S1R and S2 are composed of things 
> belonging to SR :
>
> sage: map(lambda t:type(t), S1R)
> [<type 'sage.symbolic.expression.Expression'>,
>  <type 'sage.symbolic.expression.Expression'>,
>  <type 'sage.symbolic.expression.Expression'>,
>  <type 'sage.symbolic.expression.Expression'>]
> sage: map(lambda t:type(t), S2)
> [<type 'sage.symbolic.expression.Expression'>,
>  <type 'sage.symbolic.expression.Expression'>,
>  <type 'sage.symbolic.expression.Expression'>,
>  <type 'sage.symbolic.expression.Expression'>]
>
> The reverse conversion works, however :
>
> sage: map(lambda t,u:t-u, [QQbar(t) for t in S1R], [QQbar(t) for t in S2])
> [0, 0, 0, 0]
>
> Worse : testing directly for equality CRASHES Sage :
>
> sage: map(lambda t,u:bool(t==u), S1R, S2)
> terminate called after throwing an instance of 'std::runtime_error'
>   what():  
> ------------------------------------------------------------------------
>
> /usr/local/sage-7.0/local/lib/python2.7/site-packages/sage/ext/interrupt/interrupt.so(+0x3c35)[0x7f3d47047c35]
>
> /usr/local/sage-7.0/local/lib/python2.7/site-packages/sage/ext/interrupt/interrupt.so(+0x3c87)[0x7f3d47047c87]
>
> /usr/local/sage-7.0/local/lib/python2.7/site-packages/sage/ext/interrupt/interrupt.so(+0x608c)[0x7f3d4704a08c]
> /lib/x86_64-linux-gnu/libpthread.so.0(+0x10670)[0x7f3d4edc4670]
> /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37)[0x7f3d4e337657]
> /lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f3d4e338a2a]
>
> /usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x15d)[0x7f3d3a9ad35d]
> /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x8d3b6)[0x7f3d3a9ab3b6]
> /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x8d401)[0x7f3d3a9ab401]
> /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x8d619)[0x7f3d3a9ab619]
>
> /usr/local/sage-7.0/local/lib/libpynac.so.2(_Z8py_errorPKc+0x49)[0x7f3d214029c9]
>
> /usr/local/sage-7.0/local/lib/libpynac.so.2(_ZN5GiNaC7numericC1EP7_objectb+0x1b8)[0x7f3d21403508]
>
> /usr/local/sage-7.0/local/lib/libpynac.so.2(_ZNK5GiNaC7numeric3addERKS0_+0x1c2)[0x7f3d214094f2]
>
> /usr/local/sage-7.0/local/lib/libpynac.so.2(_ZN5GiNaCplERKNS_7numericES2_+0x9)[0x7f3d2140c569]
>
> /usr/local/sage-7.0/local/lib/libpynac.so.2(_ZNK5GiNaC7numeric7add_dynERKS0_+0x2d)[0x7f3d2140405d]
>
> /usr/local/sage-7.0/local/lib/libpynac.so.2(_ZN5GiNaC9expairseq21combine_overall_coeffERKNS_2exE+0x15)[0x7f3d2136f945]
>
> /usr/local/sage-7.0/local/lib/libpynac.so.2(_ZN5GiNaC9expairseq19construct_from_2_exERKNS_2exES3_+0x27d)[0x7f3d21374bed]
>
> /usr/local/sage-7.0/local/lib/libpynac.so.2(_ZN5GiNaC3addC1ERKNS_2exES3_+0x63)[0x7f3d21346633]
>
> /usr/local/sage-7.0/local/lib/libpynac.so.2(_ZN5GiNaCmiERKNS_2exES2_+0x5f)[0x7f3d2140d14f]
>
> /usr/local/sage-7.0/local/lib/libpynac.so.2(_ZNK5GiNaC10relational6decideEv+0x3e)[0x7f3d2141bede]
>
> /usr/local/sage-7.0/local/lib/python2.7/site-packages/sage/symbolic/expression.so(+0xa7108)[0x7f3d21039108]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyObject_IsTrue+0x37)[0x7f3d4f06fe17]
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(+0x54eae)[0x7f3d4f025eae]
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(+0xbc623)[0x7f3d4f08d623]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f3d4f023a73]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x3a6e)[0x7f3d4f0d634e]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f3d4f0d928c]
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(+0x835ac)[0x7f3d4f0545ac]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f3d4f023a73]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_CallObjectWithKeywords+0x47)[0x7f3d4f0d22e7]
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(+0xfd564)[0x7f3d4f0ce564]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5c8e)[0x7f3d4f0d856e]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f3d4f0d928c]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCode+0x19)[0x7f3d4f0d93a9]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5234)[0x7f3d4f0d7b14]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f3d4f0d928c]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5a42)[0x7f3d4f0d8322]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f3d4f0d928c]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5a42)[0x7f3d4f0d8322]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f3d4f0d928c]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5a42)[0x7f3d4f0d8322]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f3d4f0d928c]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5a42)[0x7f3d4f0d8322]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f3d4f0d928c]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5a42)[0x7f3d4f0d8322]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f3d4f0d928c]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5a42)[0x7f3d4f0d8322]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f3d4f0d928c]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCode+0x19)[0x7f3d4f0d93a9]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyRun_FileExFlags+0x8a)[0x7f3d4f0fca9a]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyRun_SimpleFileExFlags+0xd7)[0x7f3d4f0fde47]
>
> /usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(Py_Main+0xc3e)[0x7f3d4f1143ee]
> /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f3d4e324870]
> python(_start+0x29)[0x4006f9]
> ------------------------------------------------------------------------
> Attaching gdb to process id 11241.
>
> Saved trace to /home/charpent/.sage/crash_logs/sage_crash_qQFZhv.log
> ------------------------------------------------------------------------
> Unhandled SIGABRT: An abort() occurred in Sage.
> This probably occurred because a *compiled* component of Sage has a bug
> in it and is not properly wrapped with sig_on(), sig_off().
> Sage will now terminate.
> ------------------------------------------------------------------------
> Abandon
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to