ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 12 Jul 2019 10:57:11 -0500Constructing a number field with complex embeddinghttp://ask.sagemath.org/question/47127/constructing-a-number-field-with-complex-embedding/ I am using the function `number_field_elements_from_algebraics` in `sage.rings.qqbar` to write some algebraic numbers as elements of a number field. I am passing `embedded=True` to also construct an embedding into `QQbar`. This works fine if the algebraic numbers are real but fails if they are complex:
<pre>
sage: number_field_elements_from_algebraics([1 + sqrt(7)], embedded=True)
(Number Field in a with defining polynomial y^2 - 7 with a = 2.645751311064591?,
[a + 1],
Ring morphism:
From: Number Field in a with defining polynomial y^2 - 7 with a = 2.645751311064591?
To: Algebraic Real Field
Defn: a |--> 2.645751311064591?)
</pre>
<pre>
sage: number_field_elements_from_algebraics([1 + sqrt(-7)], embedded=True)
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-1-ac220615ad5b> in <module>()
----> 1 number_field_elements_from_algebraics([Integer(1) + sqrt(-Integer(7))], embedded=True)
/usr/lib/python2.7/site-packages/sage/rings/qqbar.pyc in number_field_elements_from_algebraics(
numbers, minimal, same_field, embedded, prec)
2242 real_case = False
2243 if embedded:
-> 2244 raise NotImplementedError
2245 # Make the numbers algebraic
2246 numbers = [mk_algebraic(_) for _ in numbers]
NotImplementedError:
</pre>
What is the reason for why only embeddings of real numbers are supported?
I modified the code in `number_field_elements_from_algebraics` to support complex embeddings by essentially removing the check for whether the numbers are real and replacing `RealIntervalField` by `ComplexIntervalField`. This seems to work and the doctests still pass with these modifications. However I am worried that there was a good reason (either mathematically or related to some sage internals) for restricting this function to the real case.
The relevant code in `sage.rings.qqbar` was introduced in these commits:
- `26dc3e4e6a26f6f613a69d57929ea492c278dad0`
- `a9045bf8a3aab2d0aa00be17e91227bc1b50262a`
Thu, 11 Jul 2019 16:31:13 -0500http://ask.sagemath.org/question/47127/constructing-a-number-field-with-complex-embedding/Answer by slelievre for <p>I am using the function <code>number_field_elements_from_algebraics</code> in <code>sage.rings.qqbar</code> to write some algebraic numbers as elements of a number field. I am passing <code>embedded=True</code> to also construct an embedding into <code>QQbar</code>. This works fine if the algebraic numbers are real but fails if they are complex:</p>
<pre>sage: number_field_elements_from_algebraics([1 + sqrt(7)], embedded=True)
(Number Field in a with defining polynomial y^2 - 7 with a = 2.645751311064591?,
[a + 1],
Ring morphism:
From: Number Field in a with defining polynomial y^2 - 7 with a = 2.645751311064591?
To: Algebraic Real Field
Defn: a |--> 2.645751311064591?)
</pre>
<pre>sage: number_field_elements_from_algebraics([1 + sqrt(-7)], embedded=True)
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-1-ac220615ad5b> in <module>()
----> 1 number_field_elements_from_algebraics([Integer(1) + sqrt(-Integer(7))], embedded=True)
/usr/lib/python2.7/site-packages/sage/rings/qqbar.pyc in number_field_elements_from_algebraics(
numbers, minimal, same_field, embedded, prec)
2242 real_case = False
2243 if embedded:
-> 2244 raise NotImplementedError
2245 # Make the numbers algebraic
2246 numbers = [mk_algebraic(_) for _ in numbers]
NotImplementedError:
</pre>
<p>What is the reason for why only embeddings of real numbers are supported?</p>
<p>I modified the code in <code>number_field_elements_from_algebraics</code> to support complex embeddings by essentially removing the check for whether the numbers are real and replacing <code>RealIntervalField</code> by <code>ComplexIntervalField</code>. This seems to work and the doctests still pass with these modifications. However I am worried that there was a good reason (either mathematically or related to some sage internals) for restricting this function to the real case.</p>
<p>The relevant code in <code>sage.rings.qqbar</code> was introduced in these commits:</p>
<ul>
<li><code>26dc3e4e6a26f6f613a69d57929ea492c278dad0</code></li>
<li><code>a9045bf8a3aab2d0aa00be17e91227bc1b50262a</code></li>
</ul>
http://ask.sagemath.org/question/47127/constructing-a-number-field-with-complex-embedding/?answer=47135#post-id-47135Having defined:
sage: a = sqrt(-7)
This works:
sage: number_field_elements_from_algebraics([a])
(Number Field in a with defining polynomial y^2 - y + 2,
[-2*a + 1],
Ring morphism:
From: Number Field in a with defining polynomial y^2 - y + 2
To: Algebraic Field
Defn: a |--> 0.50000000000000000? - 1.322875655532296?*I)
This fails:
sage: number_field_elements_from_algebraics([a], embedded=True)
Traceback (most recent call last)
...
NotImplementedError:
The reason for why only embeddings of real numbers are supported
is that nobody has done it yet. If you can do it, your contribution will
be appreciated.
Regarding your worry that there was a good reason: if so, the correct
thing to do would have been to add as a comment about the reason,
and to raise a `ValueError` rather than a `NotImplementedError`.Fri, 12 Jul 2019 05:42:51 -0500http://ask.sagemath.org/question/47127/constructing-a-number-field-with-complex-embedding/?answer=47135#post-id-47135Answer by tmonteil for <p>I am using the function <code>number_field_elements_from_algebraics</code> in <code>sage.rings.qqbar</code> to write some algebraic numbers as elements of a number field. I am passing <code>embedded=True</code> to also construct an embedding into <code>QQbar</code>. This works fine if the algebraic numbers are real but fails if they are complex:</p>
<pre>sage: number_field_elements_from_algebraics([1 + sqrt(7)], embedded=True)
(Number Field in a with defining polynomial y^2 - 7 with a = 2.645751311064591?,
[a + 1],
Ring morphism:
From: Number Field in a with defining polynomial y^2 - 7 with a = 2.645751311064591?
To: Algebraic Real Field
Defn: a |--> 2.645751311064591?)
</pre>
<pre>sage: number_field_elements_from_algebraics([1 + sqrt(-7)], embedded=True)
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-1-ac220615ad5b> in <module>()
----> 1 number_field_elements_from_algebraics([Integer(1) + sqrt(-Integer(7))], embedded=True)
/usr/lib/python2.7/site-packages/sage/rings/qqbar.pyc in number_field_elements_from_algebraics(
numbers, minimal, same_field, embedded, prec)
2242 real_case = False
2243 if embedded:
-> 2244 raise NotImplementedError
2245 # Make the numbers algebraic
2246 numbers = [mk_algebraic(_) for _ in numbers]
NotImplementedError:
</pre>
<p>What is the reason for why only embeddings of real numbers are supported?</p>
<p>I modified the code in <code>number_field_elements_from_algebraics</code> to support complex embeddings by essentially removing the check for whether the numbers are real and replacing <code>RealIntervalField</code> by <code>ComplexIntervalField</code>. This seems to work and the doctests still pass with these modifications. However I am worried that there was a good reason (either mathematically or related to some sage internals) for restricting this function to the real case.</p>
<p>The relevant code in <code>sage.rings.qqbar</code> was introduced in these commits:</p>
<ul>
<li><code>26dc3e4e6a26f6f613a69d57929ea492c278dad0</code></li>
<li><code>a9045bf8a3aab2d0aa00be17e91227bc1b50262a</code></li>
</ul>
http://ask.sagemath.org/question/47127/constructing-a-number-field-with-complex-embedding/?answer=47133#post-id-47133I would say that `1 + sqrt(7)` could be uniformly chosen to the be the unique positive root of `(x-1)^2-7`, while there is no canonical choice for `(x-1)^2+7`. However, the problem should be in transforming the symbolic expression `1 + sqrt(-7)` into an algebraic number, but once an element of `QQbar` is defined, i do not see any problem (an element of `QQbar` *is* embedded in the complex field). So for me, there should be an error, but it should appear when calling `QQbar(1 + sqrt(-7))`.
Fri, 12 Jul 2019 03:33:35 -0500http://ask.sagemath.org/question/47127/constructing-a-number-field-with-complex-embedding/?answer=47133#post-id-47133Comment by mvk for <p>I would say that <code>1 + sqrt(7)</code> could be uniformly chosen to the be the unique positive root of <code>(x-1)^2-7</code>, while there is no canonical choice for <code>(x-1)^2+7</code>. However, the problem should be in transforming the symbolic expression <code>1 + sqrt(-7)</code> into an algebraic number, but once an element of <code>QQbar</code> is defined, i do not see any problem (an element of <code>QQbar</code> <em>is</em> embedded in the complex field). So for me, there should be an error, but it should appear when calling <code>QQbar(1 + sqrt(-7))</code>.</p>
http://ask.sagemath.org/question/47127/constructing-a-number-field-with-complex-embedding/?comment=47145#post-id-47145Thanks!
I am a bit confused though: Why can we not choose the solution with positive imaginary part for `(x-1)^2+7`? In fact, isn't this what sage is doing when it returns `+I` (as opposed to `-I`) for `QQbar(sqrt(-1))`?Fri, 12 Jul 2019 10:57:11 -0500http://ask.sagemath.org/question/47127/constructing-a-number-field-with-complex-embedding/?comment=47145#post-id-47145