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.Sat, 21 Feb 2015 04:58:34 +0100Number field containing real/imaginary part of algebraic numberhttps://ask.sagemath.org/question/25822/number-field-containing-realimaginary-part-of-algebraic-number/I have a number field N with an embedding into C (e.g., NumberField(x^3+3, 'z', 0.7+1.2j)).
I would like the smallest number field N' that contains all Re(z) and Im(z) for z in N.
I would also like a mapping from x in N to (Re(x), Im(x) in N'xN' - or at least know what Re(z) and Im(z) is in N' for the generator z of N.
What is a good way of doing this?
I was thinking along the lines of N.composite_fields(NumberField(N.defining_polynomial, 'z', embedding=ComplexField()(N.gen_embedding()).conjugate()),both_maps=True). But I ran into http://trac.sagemath.org/ticket/14164 with this occasionally. Is there a better way of doing it?Fri, 13 Feb 2015 19:47:13 +0100https://ask.sagemath.org/question/25822/number-field-containing-realimaginary-part-of-algebraic-number/Answer by vdelecroix for <p>I have a number field N with an embedding into C (e.g., NumberField(x^3+3, 'z', 0.7+1.2j)).
I would like the smallest number field N' that contains all Re(z) and Im(z) for z in N.
I would also like a mapping from x in N to (Re(x), Im(x) in N'xN' - or at least know what Re(z) and Im(z) is in N' for the generator z of N.</p>
<p>What is a good way of doing this?</p>
<p>I was thinking along the lines of N.composite_fields(NumberField(N.defining_polynomial, 'z', embedding=ComplexField()(N.gen_embedding()).conjugate()),both_maps=True). But I ran into <a href="http://trac.sagemath.org/ticket/14164">http://trac.sagemath.org/ticket/14164</a> with this occasionally. Is there a better way of doing it?</p>
https://ask.sagemath.org/question/25822/number-field-containing-realimaginary-part-of-algebraic-number/?answer=25831#post-id-25831Here is a solution going through QQbar. You first need to create your element as an element of QQbar as follows
sage: x = polygen(ZZ)
sage: a = QQbar.polynomial_root(x^3 + 3, CIF((0.6,0.8),(1.1,1.3)))
sage: a
0.7211247851537042? + 1.249024766483407?*I
Then, there is a ready made function to build the number field that contain a given number of elements
sage: number_field_elements_from_algebraics([a.real(), a.imag()], minimal=True)
(Number Field in a with defining polynomial y^6 - 3,
[1/2*a^2, 1/2*a^5],
Ring morphism:
From: Number Field in a with defining polynomial y^6 - 3
To: Algebraic Real Field
Defn: a |--> 1.200936955176003?)
The output is a triple that consists of a number field, the two elements you are looking for and a morphism to QQbar.
VincentSun, 15 Feb 2015 17:17:44 +0100https://ask.sagemath.org/question/25822/number-field-containing-realimaginary-part-of-algebraic-number/?answer=25831#post-id-25831Comment by matthias for <p>Here is a solution going through QQbar. You first need to create your element as an element of QQbar as follows</p>
<pre><code>sage: x = polygen(ZZ)
sage: a = QQbar.polynomial_root(x^3 + 3, CIF((0.6,0.8),(1.1,1.3)))
sage: a
0.7211247851537042? + 1.249024766483407?*I
</code></pre>
<p>Then, there is a ready made function to build the number field that contain a given number of elements</p>
<pre><code>sage: number_field_elements_from_algebraics([a.real(), a.imag()], minimal=True)
(Number Field in a with defining polynomial y^6 - 3,
[1/2*a^2, 1/2*a^5],
Ring morphism:
From: Number Field in a with defining polynomial y^6 - 3
To: Algebraic Real Field
Defn: a |--> 1.200936955176003?)
</code></pre>
<p>The output is a triple that consists of a number field, the two elements you are looking for and a morphism to QQbar.</p>
<p>Vincent</p>
https://ask.sagemath.org/question/25822/number-field-containing-realimaginary-part-of-algebraic-number/?comment=25876#post-id-25876Thanks so much, I got it to work with:
QQbar.polynomial_root(number_field.defining_polynomial(), CIF(number_field.gen_embedding())Sat, 21 Feb 2015 04:57:32 +0100https://ask.sagemath.org/question/25822/number-field-containing-realimaginary-part-of-algebraic-number/?comment=25876#post-id-25876Answer by tmonteil for <p>I have a number field N with an embedding into C (e.g., NumberField(x^3+3, 'z', 0.7+1.2j)).
I would like the smallest number field N' that contains all Re(z) and Im(z) for z in N.
I would also like a mapping from x in N to (Re(x), Im(x) in N'xN' - or at least know what Re(z) and Im(z) is in N' for the generator z of N.</p>
<p>What is a good way of doing this?</p>
<p>I was thinking along the lines of N.composite_fields(NumberField(N.defining_polynomial, 'z', embedding=ComplexField()(N.gen_embedding()).conjugate()),both_maps=True). But I ran into <a href="http://trac.sagemath.org/ticket/14164">http://trac.sagemath.org/ticket/14164</a> with this occasionally. Is there a better way of doing it?</p>
https://ask.sagemath.org/question/25822/number-field-containing-realimaginary-part-of-algebraic-number/?answer=25832#post-id-25832I guess you want to stay within the framework of number fields that Sage offers. What you need is to get the generator of your embedded field `F` as an algebraic number. You can try to get it as follows:
sage: F = NumberField(x^3+3, 'z', embedding=0.7+1.2j)
sage: F.gen_embedding()
0.7211247851537042? + 1.249024766483407?*I
Unfortunately, this number is not an algebraic number but a kind of infinite sequence of digits, known as lazy expansion, for which you can not easily recover the algebraic number it comes from:
sage: F.gen_embedding().parent()
Complex Lazy Field
sage: QQbar(F.gen_embedding())
TypeError: Illegal initializer for algebraic number
So, we have to look at others methods your (embedded) number field offers. If we have the embedding as morphism from `F` to the `Algebraic Field` we would be done. Let us try:
sage: F.embeddings(QQbar)
[
Ring morphism:
From: Number Field in z with defining polynomial x^3 + 3
To: Algebraic Field
Defn: z |--> -1.442249570307409?,
Ring morphism:
From: Number Field in z with defining polynomial x^3 + 3
To: Algebraic Field
Defn: z |--> 0.7211247851537042? - 1.249024766483407?*I,
Ring morphism:
From: Number Field in z with defining polynomial x^3 + 3
To: Algebraic Field
Defn: z |--> 0.7211247851537042? + 1.249024766483407?*I
]
While the documentation `F.embeddings?` says "If possible, the most natural embedding of self into K is put first in the list.", you can see that this method do not care about the embedding you provided (which should have been considerd as the most natural) since it did not put that embedding first, it just chosed the fanciest one.
There should be a method that is able to select the embedding you provided as a morphism into `QQbar` !!!
Note that we have:
sage: F.coerce_embedding()
Generic morphism:
From: Number Field in z with defining polynomial x^3 + 3
To: Complex Lazy Field
Defn: z -> 0.7211247851537042? + 1.249024766483407?*I
But again, it falls into the `ComplexLazyField`, so it is useless for our purpose.
For me, the general issue with embedded number fields in Sage is that the number field does not care much about the embedding you provided. This issue points a general problem with number fields in Sage: there is no specific class for "embedded number field", the fact that a number field is embedded or not is just a `._embedding` attribute within the same class `NumberField` (while the mathematical objects are really different), so you can define an embedding, but then the number field does not offer additional specific methods for that (in particular, it can not select the correct embedding from within `F.embeddings(QQbar)`, which is a pity).
What you can do is to discover by yourself which embedding into `QQbar` from the list corresponds to the single embedding into `CLF` (stands for `ComplexLazyField`). A trick is to extend the morphism from `QQbar` to `CLF` and check for equality:
sage: def my_embedding_as_qqbar(K):
....: for f in F.embeddings(QQbar):
....: if f.extend_codomain(CLF) == K.coerce_embedding():
....: return f
sage: f = my_embedding_as_qqbar(F) ; f
Ring morphism:
From: Number Field in z with defining polynomial x^3 + 3
To: Algebraic Field
Defn: z |--> 0.7211247851537042? + 1.249024766483407?*I
Then it is easy to get real and imaginary of the image of the generator parts and start working with them:
sage: r = f.im_gens()[0].real() ; r
0.7211247851537042?
sage: i = f.im_gens()[0].imag() ; i
1.249024766483407?
sage: r.parent()
Algebraic Real Field
sage: r.minpoly()
x^3 - 3/8
sage: i.minpoly()
x^6 - 243/64
It is an interesting task to define a distinct (perhaps inherited) well defined `EmbeddedNumberField` class with additional methods, in particular `F.embedding(field)`.
Sun, 15 Feb 2015 18:28:41 +0100https://ask.sagemath.org/question/25822/number-field-containing-realimaginary-part-of-algebraic-number/?answer=25832#post-id-25832Comment by matthias for <div class="snippet"><p>I guess you want to stay within the framework of number fields that Sage offers. What you need is to get the generator of your embedded field <code>F</code> as an algebraic number. You can try to get it as follows:</p>
<pre><code>sage: F = NumberField(x^3+3, 'z', embedding=0.7+1.2j)
sage: F.gen_embedding()
0.7211247851537042? + 1.249024766483407?*I
</code></pre>
<p>Unfortunately, this number is not an algebraic number but a kind of infinite sequence of digits, known as lazy expansion, for which you can not easily recover the algebraic number it comes from:</p>
<pre><code>sage: F.gen_embedding().parent()
Complex Lazy Field
sage: QQbar(F.gen_embedding())
TypeError: Illegal initializer for algebraic number
</code></pre>
<p>So, we have to look at others methods your (embedded) number field offers. If we have the embedding as morphism from <code>F</code> to the <code>Algebraic Field</code> we would be done. Let us try:</p>
<pre><code>sage: F.embeddings(QQbar)
[
Ring morphism:
From: Number Field in z with defining polynomial x^3 + 3
To: Algebraic Field
Defn: z |--> -1.442249570307409?,
Ring morphism:
From: Number Field in z with defining polynomial x^3 + 3
To: Algebraic Field
Defn: z |--> 0.7211247851537042? - 1.249024766483407?*I,
Ring morphism:
From: Number Field in z with defining polynomial x^3 + 3
To: Algebraic Field
Defn: z |--> 0.7211247851537042? + 1.249024766483407?*I
]
</code></pre>
<p>While the documentation <code>F.embeddings?</code> says "If possible, the most natural embedding of self into K is put first in the list.", you can see that this method do not care about the embedding you provided (which should have been considerd as the most natural) since it did not put that embedding first, it just chosed the fanciest one.</p>
<p>There should be a method that is able to select the embedding you provided as a morphism into <code>QQbar</code> !!!</p>
<p>Note that we have:</p>
<pre><code>sage: F.coerce_embedding()
Generic morphism:
From: Number Field in z with defining polynomial x^3 + 3
To: Complex Lazy Field
Defn: z -> 0.7211247851537042? + 1.249024766483407?*I
</code></pre>
<p>But again, it falls into the <code>ComplexLazyField</code>, so it is useless for our purpose.</p>
<p>For me, the general issue with embedded number fields in Sage is that the number field does not care much about the embedding you provided. This issue points a general problem with number fields in Sage: there is no specific class for "embedded number field", the fact that a number field is embedded or not is just a <code>._embedding</code> attribute within the same class <code>NumberField</code> (while the mathematical objects are really different), so you can define an embedding, but then the number field does not offer additional specific methods for that (in particular, it can not select the correct embedding from within <code>F.embeddings(QQbar)</code>, which is a pity).</p>
<p>What you can do is to discover by yourself which embedding into <code>QQbar</code> from the list corresponds to the single embedding into <code>CLF</code> (stands for <code>ComplexLazyField</code>). A trick is to extend the morphism from <code>QQbar</code> to <code>CLF</code> and check for equality:</p>
<pre><code>sage: def my_embedding_as_qqbar(K):
....: for f in F.embeddings(QQbar):
....: if f.extend_codomain(CLF ...</code></pre><span class="expander"> <a>(more)</a></span></div>https://ask.sagemath.org/question/25822/number-field-containing-realimaginary-part-of-algebraic-number/?comment=25877#post-id-25877This is insightful, but the other solution is ultimately much shorter.Sat, 21 Feb 2015 04:58:34 +0100https://ask.sagemath.org/question/25822/number-field-containing-realimaginary-part-of-algebraic-number/?comment=25877#post-id-25877