#14982: Coercion from base ring fails for some polynomial rings over number
fields
with embeddings
-------------------------------+--------------------------
Reporter: mmezzarobba | Owner:
Type: defect | Status: new
Priority: major | Milestone: sage-5.12
Component: coercion | Resolution:
Keywords: | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Dependencies:
Stopgaps: |
-------------------------------+--------------------------
Changes (by mmezzarobba):
* cc: robertwb, SimonKing (added)
Comment:
Apparently, the problem is more general stems from the policy of
`Parent.discover_coerce_map_from` of always giving priority to coercions
that start with applying an embedding over those provided by
`_coerce_map_from_`.
In the special case of this ticket, a workaround would be to revert part
of a3c5958b8e6983a3ef8466d0bd0b6ce09fd32d41 so that the
`BaseringInjection` gets registered as early as possible:
{{{
--- a/src/sage/rings/polynomial/polynomial_ring.py
+++ b/src/sage/rings/polynomial/polynomial_ring.py
@@ -283,9 +283,11 @@ class
PolynomialRing_general(sage.algebras.algebra.Algebra):
# since we want to use PolynomialBaseringInjection.
sage.algebras.algebra.Algebra.__init__(self, base_ring,
names=name, normalize=True, category=category)
self.__generator = self._polynomial_class(self, [0,1],
is_gen=True)
+ base_inject = PolynomialBaseringInjection(base_ring, self)
+ self._unset_coercions_used()
self._populate_coercion_lists_(
- #coerce_list = [base_inject],
- #convert_list = [list, base_inject],
+ coerce_list = [base_inject],
+ convert_list = [list, base_inject],
convert_method_name = '_polynomial_')
@@ -552,8 +554,8 @@ class
PolynomialRing_general(sage.algebras.algebra.Algebra):
"""
# In the first place, handle the base ring
base_ring = self.base_ring()
- if P is base_ring:
- return PolynomialBaseringInjection(base_ring, self)
+ #if P is base_ring:
+ # return PolynomialBaseringInjection(base_ring, self)
# handle constants that canonically coerce into self.base_ring()
# first, if possible
try:
}}}
(I didn't check whether this breaks anything else.)
But the same issue potentially affects anything constructed over a base
ring with `coerce_embedding`. At best, a suboptimal coercion is found:
{{{
sage: M = MatrixSpace(L, 2, 2)
sage: M.coerce_map_from(L)
Composite map:
From: Number Field in b with defining polynomial x^2 + 2
To: Full MatrixSpace of 2 by 2 dense matrices over Number Field in b
with defining polynomial x^2 + 2
Defn: Generic morphism:
From: Number Field in b with defining polynomial x^2 + 2
To: Number Field in a with defining polynomial x^2 + 1/2
Defn: b -> -2*a
then
Call morphism:
From: Number Field in a with defining polynomial x^2 + 1/2
To: Full MatrixSpace of 2 by 2 dense matrices over Number
Field in b with defining polynomial x^2 + 2
sage: PowerSeriesRing(L, 'x').coerce_map_from(L)
Composite map:
From: Number Field in b with defining polynomial x^2 + 2
To: Power Series Ring in x over Number Field in b with defining
polynomial x^2 + 2
Defn: Generic morphism:
From: Number Field in b with defining polynomial x^2 + 2
To: Number Field in a with defining polynomial x^2 + 1/2
Defn: b -> -2*a
then
Conversion map:
From: Number Field in a with defining polynomial x^2 + 1/2
To: Power Series Ring in x over Number Field in b with
defining polynomial x^2 + 2
}}}
and at worst the construction itself fails (well, I'm assuming it's the
same issue as above, but I didn't check in detail):
{{{
sage: L.extension(x^3+x+1, 'c')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call
last)
<ipython-input-28-b42564719919> in <module>()
----> 1 L.extension(x**Integer(3)+x+Integer(1), 'c')
/home/marc/co/sage/local/lib/python2.7/site-
packages/sage/rings/number_field/number_field.pyc in extension(self, poly,
name, names, check, embedding)
4173 raise TypeError, "the variable name must be
specified."
4174 from sage.rings.number_field.number_field_rel import
NumberField_relative
-> 4175 return NumberField_relative(self, poly, str(name),
check=check, embedding=embedding)
4176
4177 def factor(self, n):
/home/marc/co/sage/local/lib/python2.7/site-
packages/sage/rings/number_field/number_field_rel.pyc in __init__(self,
base, polynomial, name, latex_name, names, check, embedding)
301
302 v[0] = self._gen_relative()
--> 303 v = [self(x) for x in v]
304 self.__gens = tuple(v)
305 self._zero_element = self(0)
/home/marc/co/sage/local/lib/python2.7/site-
packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__
(sage/structure/parent.c:8078)()
/home/marc/co/sage/local/lib/python2.7/site-
packages/sage/structure/parent.so in
sage.structure.parent.Parent.convert_map_from
(sage/structure/parent.c:15826)()
/home/marc/co/sage/local/lib/python2.7/site-
packages/sage/structure/parent.so in
sage.structure.parent.Parent.discover_convert_map_from
(sage/structure/parent.c:15991)()
/home/marc/co/sage/local/lib/python2.7/site-
packages/sage/structure/parent.so in
sage.structure.parent.Parent.coerce_map_from
(sage/structure/parent.c:14563)()
/home/marc/co/sage/local/lib/python2.7/site-
packages/sage/structure/parent.so in
sage.structure.parent.Parent.discover_coerce_map_from
(sage/structure/parent.c:14932)()
/home/marc/co/sage/local/lib/python2.7/site-
packages/sage/structure/parent.so in
sage.structure.parent.Parent.coerce_map_from
(sage/structure/parent.c:14563)()
/home/marc/co/sage/local/lib/python2.7/site-
packages/sage/structure/parent.so in
sage.structure.parent.Parent.discover_coerce_map_from
(sage/structure/parent.c:14985)()
/home/marc/co/sage/local/lib/python2.7/site-
packages/sage/structure/parent_old.so in
sage.structure.parent_old.Parent._coerce_map_from_
(sage/structure/parent_old.c:6658)()
/home/marc/co/sage/local/lib/python2.7/site-
packages/sage/rings/number_field/number_field_rel.pyc in
_coerce_map_from_(self, R)
1031 mor = self.base_field().coerce_map_from(R)
1032 if mor is not None:
-> 1033 return self.coerce_map_from(self.base_field()) * mor
1034
1035 def _rnfeltreltoabs(self, element, check=False):
/home/marc/co/sage/local/lib/python2.7/site-
packages/sage/categories/map.so in sage.categories.map.Map.__mul__
(sage/categories/map.c:4796)()
AttributeError: 'NoneType' object has no attribute 'domain'
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/14982#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.