Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem understanding coercions.

Let :

sage:  w = x^4 - (1+3*i)*x^3 - (2-4*i)*x^2 + (6-2*i)*x - 4 - 4*i

We can try to get its roots by (at least) two means : 1) Solution of a quartic :

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
sage: S1R=[t.subs({sqrt(2*I):1+I}) for t in S1];S1R
[I - 1, 2*I, -I + 1, I + 1]

2) Roots of a polynom

sage: S2=[SR(t[0]) for t in w.roots(ring=QQbar)];S2
[-1 + 1*I, 2*I, 1 - 1*I, 1 + 1*I]

I am convinced tjat those two solutions are equal. But I fail to convince Sage :

sage: map(lambda t,u:t-u, S1R, S2)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-be2e4183b522> in <module>()
----> 1 map(lambda t,u:t-u, S1R, S2)

<ipython-input-7-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'

However, both lists are composed of some things seemongly 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'>]

Worse, if I try to directly test for inequality, Sage CRASHES :

sage: 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)[0x7f53046bcc35]
/usr/local/sage-7.0/local/lib/python2.7/site-packages/sage/ext/interrupt/interrupt.so(+0x3c87)[0x7f53046bcc87]
/usr/local/sage-7.0/local/lib/python2.7/site-packages/sage/ext/interrupt/interrupt.so(+0x608c)[0x7f53046bf08c]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x10670)[0x7f530c439670]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37)[0x7f530b9ac657]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f530b9ada2a]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x15d)[0x7f52f803c35d]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x8d3b6)[0x7f52f803a3b6]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x8d401)[0x7f52f803a401]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x8d619)[0x7f52f803a619]
/usr/local/sage-7.0/local/lib/libpynac.so.2(_Z8py_errorPKc+0x49)[0x7f52dea919c9]
/usr/local/sage-7.0/local/lib/libpynac.so.2(_ZN5GiNaC7numericC1EP7_objectb+0x1b8)[0x7f52dea92508]
/usr/local/sage-7.0/local/lib/libpynac.so.2(_ZNK5GiNaC7numeric3addERKS0_+0x1c2)[0x7f52dea984f2]
/usr/local/sage-7.0/local/lib/libpynac.so.2(_ZN5GiNaCplERKNS_7numericES2_+0x9)[0x7f52dea9b569]
/usr/local/sage-7.0/local/lib/libpynac.so.2(_ZNK5GiNaC7numeric7add_dynERKS0_+0x2d)[0x7f52dea9305d]
/usr/local/sage-7.0/local/lib/libpynac.so.2(_ZN5GiNaC9expairseq21combine_overall_coeffERKNS_2exE+0x15)[0x7f52de9fe945]
/usr/local/sage-7.0/local/lib/libpynac.so.2(_ZN5GiNaC9expairseq19construct_from_2_exERKNS_2exES3_+0x27d)[0x7f52dea03bed]
/usr/local/sage-7.0/local/lib/libpynac.so.2(_ZN5GiNaC3addC1ERKNS_2exES3_+0x63)[0x7f52de9d5633]
/usr/local/sage-7.0/local/lib/libpynac.so.2(_ZN5GiNaCmiERKNS_2exES2_+0x5f)[0x7f52dea9c14f]
/usr/local/sage-7.0/local/lib/libpynac.so.2(_ZNK5GiNaC10relational6decideEv+0x3e)[0x7f52deaaaede]
/usr/local/sage-7.0/local/lib/python2.7/site-packages/sage/symbolic/expression.so(+0xa7108)[0x7f52de6c8108]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyObject_IsTrue+0x37)[0x7f530c6e4e17]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyObject_RichCompareBool+0x2c)[0x7f530c6e59cc]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(+0x8786c)[0x7f530c6cd86c]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyObject_RichCompare+0x72)[0x7f530c6e55d2]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x41b5)[0x7f530c74ba95]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f530c74e28c]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCode+0x19)[0x7f530c74e3a9]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5234)[0x7f530c74cb14]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f530c74e28c]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5a42)[0x7f530c74d322]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f530c74e28c]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5a42)[0x7f530c74d322]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f530c74e28c]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5a42)[0x7f530c74d322]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f530c74e28c]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5a42)[0x7f530c74d322]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f530c74e28c]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5a42)[0x7f530c74d322]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f530c74e28c]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5a42)[0x7f530c74d322]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x81c)[0x7f530c74e28c]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyEval_EvalCode+0x19)[0x7f530c74e3a9]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyRun_FileExFlags+0x8a)[0x7f530c771a9a]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(PyRun_SimpleFileExFlags+0xd7)[0x7f530c772e47]
/usr/local/sage-7.0/local/lib/libpython2.7.so.1.0(Py_Main+0xc3e)[0x7f530c7893ee]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f530b999870]
python(_start+0x29)[0x4006f9]
------------------------------------------------------------------------
Attaching gdb to process id 10517.

Saved trace to /home/charpent/.sage/crash_logs/sage_crash_w2E5Tn.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

Hence two questions :

  1. What in S2 is not convertible to SR and why ?
  2. How should I test for equality ?

I'm a bit lost...