Help on coercicion (Sage Crash inside).

54 views
Skip to first unread message

Emmanuel Charpentier

unread,
Jan 17, 2016, 12:39:43 PM1/17/16
to sage-support
(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


William Stein

unread,
Jan 17, 2016, 1:00:02 PM1/17/16
to sage-support
On Sun, Jan 17, 2016 at 9:39 AM, Emmanuel Charpentier
<emanuel.c...@gmail.com> 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:

They aren't the same. The "I" you're using everywhere is a number
field element. However, when you do SR(...root in QQbar...), you're
making a completely different and incompatible I. The notation

SomeParent(...)

is potentially dangerous: <rant> it means "make something in
SomeParent from the input possibly without respecting the coercion
model". It's what people do when the get frustrated -- it's a sort of
automated version of copy/paste. It's like Magma's "SomeParent![crazy
thing]", and is by far the most likely source of bugs in code.
</rant>

If you do:

reset()
a = (x^2+1).roots(ring=QQbar)[1][0]
b = I.pyobject()
a, b
parent(a), parent(b)

you'll see the two underlying elements that you're trying to mix.
One is a number field element, and the other is an element of QQbar.
Number fields elements don't mix with elements of QQbar without
explicitly applying an embedding morphism.

That said, I vaguely recall at some point that a fixed choice of
embedding was something maybe added to number fields. It would likely
make a lot more sense also for the I in SR to the one from QQbar
rather than the one from NumberField(x^2+1). However, the one from
NumberField(x^2+1) is a *lot* faster (orders of magnitude!), so it's
no so clear.

I'm not at all saying you haven't hit on a serious bug. However, the
above remarks might help whoever works on it, maybe.

William
> --
> 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 sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.



--
William (http://wstein.org)

Emmanuel Charpentier

unread,
Jan 17, 2016, 1:10:51 PM1/17/16
to sage-support
Thanks a lot for this answer. This is somewhat clearer for me. Now, I have to understand coercions between THREE sets that a (non-professionnal-mathematician) human thinks (vaguely) as one : $\mathbb{C}$.

I suppose that's a price to pay for using Sage. Probably "obviously" the Right Thing to a professional mathematician, but a (non-obvious) hurdle for "engineering types" such as me.

Thanks again !

--
Emmanuel Charpentier

Volker Braun

unread,
Jan 17, 2016, 1:27:20 PM1/17/16
to sage-support
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]

William Stein

unread,
Jan 17, 2016, 1:37:14 PM1/17/16
to sage-support
Hi,

Does anybody understand number field embeddings
http://doc.sagemath.org/html/en/reference/number_fields/sage/rings/number_field/number_field_morphisms.html

and whether the default I in SR (i.e., NumberField(x^2+1)) is equipped
with any embeddings. The above reference manual shows how to make
number fields with embeddings, but I couldn't see how to query a
number field for its embeddings. Obviously, I could figure this out
by reading the source, but I'm don't have time right now. I'm curious
though, since I want to talk about this in my grad course on
Wednesday, and it's relevant to the bug.

I'm posting worksheets like this for my class:

https://cloud.sagemath.com/projects/b85dd1b3-3f5f-4c2d-b503-242612561b9e/files/lectures/2016-01-15/2016-01-15-part0-QQbar.sagews

Nils Bruin

unread,
Jan 17, 2016, 3:42:45 PM1/17/16
to sage-support
On Sunday, January 17, 2016 at 10:37:14 AM UTC-8, William wrote:
Hi,

Does anybody understand number field embeddings
   http://doc.sagemath.org/html/en/reference/number_fields/sage/rings/number_field/number_field_morphisms.html

and whether the default I in SR (i.e., NumberField(x^2+1)) is equipped
with any embeddings.

I wouldn't claim I understand exactly what sage does there. I do know that in the coercion model, there is a slot available for pretty much any parent to have a coercion *to* some other structure (for the most part, coercions are stored on the target rather than on the domain). This is mainly to accommodate, e.g., numberfields to act as "subfields" of CC while still being able to have a shorter lifetime than CC.

The parent of I.pyobject() has one of those registered:

sage: CC.coerce_map_from(parent(I.pyobject()))
Composite map:
  From: Number Field in I with defining polynomial x^2 + 1
  To:   Complex Field with 53 bits of precision
  Defn:   Generic morphism:
          From: Number Field in I with defining polynomial x^2 + 1
          To:   Complex Lazy Field
          Defn: I -> 1*I
        then
          Conversion map:
          From: Complex Lazy Field
          To:   Complex Field with 53 bits of precision

whereas a "normal" imaginary quadratic field does not:

sage: CC.coerce_map_from(NumberField(x^2+1,"ii")) is None
True

This doesn't seem to be what triggers the path to SR, though:

sage: SR.coerce_map_from(parent(I.pyobject()))
Conversion via _symbolic_ method map:
  From: Number Field in I with defining polynomial x^2 + 1
  To:   Symbolic Ring

sage: SR.coerce_map_from(NumberField(x^2+1,"ii")) is None
True

so it seems the coercion for I.pyobject() is in fact registered on SR (hence nailing I.pyobject().parent() in memory, which isn't an issue)

Volker Braun

unread,
Jan 17, 2016, 4:42:44 PM1/17/16
to sage-support
AlgebraicField = QQbar is a separate implementation from NumberField. The number field embeddings refer to the latter only.

William Stein

unread,
Jan 17, 2016, 4:49:13 PM1/17/16
to sage-support
On Sun, Jan 17, 2016 at 1:42 PM, Volker Braun <vbrau...@gmail.com> wrote:
> AlgebraicField = QQbar is a separate implementation from NumberField. The
> number field embeddings refer to the latter only.
>

I don't understand. The first three examples at

http://doc.sagemath.org/html/en/reference/number_fields/sage/rings/number_field/number_field_morphisms.html

are of equipping a number field with an embedding in QQbar.

William

Volker Braun

unread,
Jan 17, 2016, 5:00:48 PM1/17/16
to sage-support
What I'm trying to say is that QQbar and NumberField aren't embedded in CC in the same code path:

sage: SR(I).pyobject().parent().embeddings(CC)
[
Ring morphism:
  From: Number Field in I with defining polynomial x^2 + 1
  To:   Complex Field with 53 bits of precision
  Defn: I |--> -1.00000000000000*I,
Ring morphism:
  From: Number Field in I with defining polynomial x^2 + 1
  To:   Complex Field with 53 bits of precision
  Defn: I |--> 1.00000000000000*I
]

sage: K.<a> = NumberField(x^2+1, embedding=CC.gen())
sage: K.embeddings(CC)
[
Ring morphism:
  From: Number Field in a with defining polynomial x^2 + 1
  To:   Complex Field with 53 bits of precision
  Defn: a |--> -1.00000000000000*I,
Ring morphism:
  From: Number Field in a with defining polynomial x^2 + 1
  To:   Complex Field with 53 bits of precision
  Defn: a |--> 1.00000000000000*I
]

sage: QQbar.embeddings(CC)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-53-8c92918ea5ef> in <module>()
----> 1 QQbar.embeddings(CC)

/home/vbraun/Code/sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.__getattr__ (/home/vbraun/Code/sage/src/build/cythonized/sage/structure/parent.c:8043)()
    853             return self.__cached_methods[name]
    854         except KeyError:
--> 855             attr = getattr_from_other_class(self, self._category.parent_class, name)
    856             self.__cached_methods[name] = attr
    857             return attr

/home/vbraun/Code/sage/src/sage/structure/misc.pyx in sage.structure.misc.getattr_from_other_class (/home/vbraun/Code/sage/src/build/cythonized/sage/structure/misc.c:1667)()
    251         dummy_error_message.cls = type(self)
    252         dummy_error_message.name = name
--> 253         raise dummy_attribute_error
    254     try:
    255         attribute = getattr(cls, name)

AttributeError: 'AlgebraicField_with_category' object has no attribute 'embeddings'


and the crash is from working with QQbar, not the NumberField

sage: bool(SR(K.gen()) == I)
True
sage: bool(SR(QQbar.gen()) == I)
CRASH
Reply all
Reply to author
Forward
0 new messages