Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 8798dd9

Browse files
committed
Simplify the logic for finding coercions between embedded number fields
1 parent 2123372 commit 8798dd9

File tree

2 files changed

+31
-47
lines changed

2 files changed

+31
-47
lines changed

src/sage/rings/number_field/number_field.py

+11-28
Original file line numberDiff line numberDiff line change
@@ -6139,35 +6139,18 @@ def _coerce_map_from_(self, R):
61396139
from sage.rings.number_field.order import is_NumberFieldOrder
61406140
if is_NumberFieldOrder(R) and self.has_coerce_map_from(R.number_field()):
61416141
return self._generic_convert_map(R)
6142-
if is_NumberField(R) and R != QQ:
6143-
if R.coerce_embedding() is not None:
6144-
if self.coerce_embedding() is not None:
6145-
try:
6146-
try:
6147-
return number_field_morphisms.EmbeddedNumberFieldMorphism(R, self)
6148-
except ValueError: # no embedding found
6149-
pass
6150-
Remb = R.coerce_embedding().codomain()
6151-
while Remb.coerce_embedding() is not None:
6152-
Remb = Remb.coerce_embedding().codomain()
6153-
semb = self.coerce_embedding().codomain()
6154-
while semb.coerce_embedding() is not None:
6155-
semb = semb.coerce_embedding().codomain()
6156-
ambient_field = pushout(Remb, semb)
6157-
# By trac #15331, EmbeddedNumberFieldMorphism has already
6158-
# tried to use this pushout. Hence, if we are here, our
6159-
# only chance for success is the algebrais closure.
6160-
if ambient_field is not None:
6161-
return number_field_morphisms.EmbeddedNumberFieldMorphism(R, self,
6162-
ambient_field.algebraic_closure())
6163-
except (AttributeError, ValueError, TypeError, NotImplementedError, sage.structure.coerce_exceptions.CoercionException),msg:
6164-
# no success at all
6165-
return
6166-
else:
6167-
# R is embedded, self isn't. So, we could only have
6168-
# the forgetful coercion. But this yields to non-commuting
6169-
# coercions, as was pointed out at ticket #8800
6142+
# R is not QQ by the above tests
6143+
if is_NumberField(R) and R.coerce_embedding() is not None:
6144+
if self.coerce_embedding() is not None:
6145+
try:
6146+
return number_field_morphisms.EmbeddedNumberFieldMorphism(R, self)
6147+
except ValueError: # no common embedding found
61706148
return None
6149+
else:
6150+
# R is embedded, self isn't. So, we could only have
6151+
# the forgetful coercion. But this yields to non-commuting
6152+
# coercions, as was pointed out at ticket #8800
6153+
return None
61716154

61726155
def base_field(self):
61736156
"""

src/sage/rings/number_field/number_field_morphisms.pyx

+20-19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ fields (generally `\RR` or `\CC`).
2020
# http://www.gnu.org/licenses/
2121
#*****************************************************************************
2222

23+
import sage.rings.complex_double
2324

2425
from sage.structure.element cimport Element
2526
from sage.categories.morphism cimport Morphism
@@ -173,34 +174,34 @@ cdef class EmbeddedNumberFieldMorphism(NumberFieldEmbedding):
173174
174175
"""
175176
if ambient_field is None:
176-
from sage.rings.complex_double import CDF
177-
default_ambient_field = CDF
178-
Kemb = K.coerce_embedding()
179-
if Kemb is None:
177+
if K.coerce_embedding() is None:
180178
raise TypeError("No embedding available for %s"%K)
181-
Kemb = Kemb.codomain()
179+
Kemb = K
182180
while Kemb.coerce_embedding() is not None:
183181
Kemb = Kemb.coerce_embedding().codomain()
184-
Lemb = L.coerce_embedding()
185-
if Lemb is None:
182+
if L.coerce_embedding() is None:
186183
raise TypeError("No embedding available for %s"%L)
187-
Lemb = Lemb.codomain()
184+
Lemb = L
188185
while Lemb.coerce_embedding() is not None:
189186
Lemb = Lemb.coerce_embedding().codomain()
190-
ambient_field = pushout(Kemb, Lemb)
187+
ambient_field = pushout(Kemb, Lemb)
188+
candidate_ambient_fields = [ambient_field, sage.rings.complex_double.CDF]
189+
try:
190+
candidate_ambient_fields.append(ambient_field.algebraic_closure())
191+
except NotImplementedError:
192+
pass
193+
else:
194+
candidate_ambient_fields = [ambient_field]
195+
196+
for ambient_field in candidate_ambient_fields:
197+
gen_image = matching_root(K.polynomial().change_ring(L), K.gen(), ambient_field=ambient_field, margin=2)
198+
if gen_image is not None:
199+
NumberFieldEmbedding.__init__(self, K, L, gen_image)
200+
self.ambient_field = ambient_field
201+
return
191202
else:
192-
default_ambient_field = None
193-
gen_image = matching_root(K.polynomial().change_ring(L), K.gen(), ambient_field=ambient_field, margin=2)
194-
if gen_image is None and default_ambient_field is not None:
195-
ambient_field = default_ambient_field
196-
gen_image = matching_root(K.polynomial().change_ring(L), K.gen(),
197-
ambient_field=ambient_field, margin=2)
198-
if gen_image is None:
199203
raise ValueError, "No consistent embedding of all of %s into %s." % (K, L)
200204

201-
NumberFieldEmbedding.__init__(self, K, L, gen_image)
202-
self.ambient_field = ambient_field
203-
204205
def section(self):
205206
"""
206207
EXAMPLES::

0 commit comments

Comments
 (0)