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

Commit 2123372

Browse files
Raise type error for number field morphisms of non-embedded number fields
1 parent 0d00bf7 commit 2123372

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

src/sage/rings/number_field/number_field.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
from sage.misc.functional import is_odd
102102
from sage.misc.misc_c import prod
103103
from sage.categories.homset import End
104+
from sage.categories.pushout import pushout
104105

105106
import sage.rings.ring
106107
from sage.misc.latex import latex_variable_name
@@ -6142,21 +6143,26 @@ def _coerce_map_from_(self, R):
61426143
if R.coerce_embedding() is not None:
61436144
if self.coerce_embedding() is not None:
61446145
try:
6145-
from sage.categories.pushout import pushout
6146-
ambient_field = pushout(R.coerce_embedding().codomain(), self.coerce_embedding().codomain())
6147-
if ambient_field is not None:
6148-
try:
6149-
# the original ambient field
6150-
return number_field_morphisms.EmbeddedNumberFieldMorphism(R, self, ambient_field)
6151-
except ValueError: # no embedding found
6152-
# there might be one in the alg. completion
6153-
return number_field_morphisms.EmbeddedNumberFieldMorphism(R, self, ambient_field.algebraic_closure() if hasattr(ambient_field,'algebraic_closure') else ambient_field)
6154-
except (ValueError, TypeError, NotImplementedError, sage.structure.coerce_exceptions.CoercionException),msg:
6155-
# no success with the pushout
61566146
try:
61576147
return number_field_morphisms.EmbeddedNumberFieldMorphism(R, self)
6158-
except (TypeError, ValueError):
6148+
except ValueError: # no embedding found
61596149
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
61606166
else:
61616167
# R is embedded, self isn't. So, we could only have
61626168
# the forgetful coercion. But this yields to non-commuting

src/sage/rings/number_field/number_field_morphisms.pyx

+33-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fields (generally `\RR` or `\CC`).
2424
from sage.structure.element cimport Element
2525
from sage.categories.morphism cimport Morphism
2626
from sage.categories.map cimport Map
27+
from sage.categories.pushout import pushout
2728

2829
from sage.rings.real_mpfr import RealField, mpfr_prec_min
2930
from sage.rings.complex_field import ComplexField
@@ -107,8 +108,7 @@ cdef class NumberFieldEmbedding(Morphism):
107108
cdef class EmbeddedNumberFieldMorphism(NumberFieldEmbedding):
108109
r"""
109110
This allows one to go from one number field in another consistently,
110-
assuming they both have specified embeddings into an ambient field
111-
(by default it looks for an embedding into `\CC`).
111+
assuming they both have specified embeddings into an ambient field.
112112
113113
EXAMPLES::
114114
@@ -161,13 +161,43 @@ cdef class EmbeddedNumberFieldMorphism(NumberFieldEmbedding):
161161
Traceback (most recent call last):
162162
...
163163
TypeError: unsupported operand parent(s) for '+': 'Number Field in a with defining polynomial x^3 + 2' and 'Number Field in a with defining polynomial x^3 + 2'
164+
165+
The following was fixed to raise a ``TypeError`` in :trac:`15331`::
166+
167+
sage: L.<i> = NumberField(x^2 + 1)
168+
sage: K = NumberField(L(i/2+3).minpoly(), names=('i0',), embedding=L(i/2+3))
169+
sage: EmbeddedNumberFieldMorphism(K, L)
170+
Traceback (most recent call last):
171+
...
172+
TypeError: No embedding available for Number Field in i with defining polynomial x^2 + 1
173+
164174
"""
165175
if ambient_field is None:
166176
from sage.rings.complex_double import CDF
167-
ambient_field = CDF
177+
default_ambient_field = CDF
178+
Kemb = K.coerce_embedding()
179+
if Kemb is None:
180+
raise TypeError("No embedding available for %s"%K)
181+
Kemb = Kemb.codomain()
182+
while Kemb.coerce_embedding() is not None:
183+
Kemb = Kemb.coerce_embedding().codomain()
184+
Lemb = L.coerce_embedding()
185+
if Lemb is None:
186+
raise TypeError("No embedding available for %s"%L)
187+
Lemb = Lemb.codomain()
188+
while Lemb.coerce_embedding() is not None:
189+
Lemb = Lemb.coerce_embedding().codomain()
190+
ambient_field = pushout(Kemb, Lemb)
191+
else:
192+
default_ambient_field = None
168193
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)
169198
if gen_image is None:
170199
raise ValueError, "No consistent embedding of all of %s into %s." % (K, L)
200+
171201
NumberFieldEmbedding.__init__(self, K, L, gen_image)
172202
self.ambient_field = ambient_field
173203

0 commit comments

Comments
 (0)