# Coerce an algebraic into a number field that contains it

Consider the following code

r = QQbar.polynomial_root(x^5-x-1,CIF(RIF(0.1, 0.2), RIF(1.0, 1.1))
F,_,_ = number_field_elements_from_algebraics(r)
F(r)


Even though r can be coerced into an element of F, this coercion doesn't happen. What is the right thing for me to do? I'm interested in computing an algebraic number field that will contain a bunch of eigenvalues and want to express all the eigenvalues as elements of the number field. I've done the obvious workaround but the limitation expressed in the sample above isn't great.

edit retag close merge delete

Sort by » oldest newest most voted

First of all, you missed a closing paranthesis on the first line. Secondly, it is better to include code that is working, that is to say include the line

sage: from sage.rings.qqbar import number_field_elements_from_algebraics


Now, if you want to convert a single element, just do

sage: K, elt, phi = r.as_number_field_element()


Then elt is the element of your number field K (that is the same thing as r). phi is the morphism from the number field K to QQbar and you can check

sage: phi(elt) == r
True

more