ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 08 Dec 2017 22:02:47 +0100Coerce an algebraic into a number field that contains ithttps://ask.sagemath.org/question/40020/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.Fri, 08 Dec 2017 20:51:20 +0100https://ask.sagemath.org/question/40020/coerce-an-algebraic-into-a-number-field-that-contains-it/Answer by vdelecroix for <p>Consider the following code</p>
<pre><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)
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/40020/coerce-an-algebraic-into-a-number-field-that-contains-it/?answer=40021#post-id-40021First 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
TrueFri, 08 Dec 2017 22:02:47 +0100https://ask.sagemath.org/question/40020/coerce-an-algebraic-into-a-number-field-that-contains-it/?answer=40021#post-id-40021