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

Commit 7e4f15e

Browse files
committed
change coercion defaults
1 parent 253200f commit 7e4f15e

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

src/sage/rings/polynomial/skew_polynomial_ring.py

+38-35
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ def __init__(self, base_ring, twist_map, name, sparse, category=None):
13131313
self._order = twist_map.order()
13141314
(self._constants, self._embed_constants) = twist_map.fixed_field()
13151315

1316-
def center(self, name='z', names=None, coerce=False):
1316+
def center(self, name='z', names=None, coerce=True):
13171317
r"""
13181318
Return the center of this skew polynomial ring.
13191319
@@ -1359,12 +1359,21 @@ def center(self, name='z', names=None, coerce=False):
13591359
sage: y.parent() is Zy
13601360
True
13611361
1362-
By default, conversion maps between the center and the skew
1363-
polynomial ring are set in both directions, but no coercion
1364-
map is defined::
1362+
By default, the canonical inclusion of the center into the skew
1363+
polynomial ring is a coercion map::
1364+
1365+
sage: S.has_coerce_map_from(Zy)
1366+
True
1367+
1368+
sage: P = y + x; P
1369+
x^3 + x
1370+
sage: P.parent()
1371+
Skew Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5
1372+
sage: P.parent() is S
1373+
True
1374+
1375+
Moreover, a conversion map in the other direction is set::
13651376
1366-
sage: S(y^2 + 2*y + 3)
1367-
x^6 + 2*x^3 + 3
13681377
sage: Zy(x^6 + 2*x^3 + 3)
13691378
y^2 + 2*y + 3
13701379
@@ -1373,32 +1382,24 @@ def center(self, name='z', names=None, coerce=False):
13731382
...
13741383
ValueError: x^2 is not in the center
13751384
1376-
We now illustrate the fact that no coercion map is set::
1377-
1378-
sage: S.has_coerce_map_from(Zy)
1379-
False
1380-
sage: Zy.has_coerce_map_from(S)
1381-
False
1382-
1383-
sage: P = y + x; P
1384-
y + x
1385-
sage: P.parent()
1386-
Univariate Polynomial Ring in y over Skew Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5
1387-
sage: P.parent() is S
1388-
False
1389-
1390-
Nevertheless, if the user wants to promote the embedding from the
1391-
center to the skew polynomial ring as a coercion map, he/she can
1392-
pass in the argument ``coerce=True``::
1385+
It is possible to disable the coercion by passing in the
1386+
argument ``coerce=False``::
13931387
1394-
sage: Zu.<u> = S.center(coerce=True)
1388+
sage: Zu.<u> = S.center(coerce=False)
13951389
sage: S.has_coerce_map_from(Zu)
1396-
True
1390+
False
13971391
13981392
sage: Q = u + x; Q
1399-
x^3 + x
1393+
u + x
1394+
sage: Q.parent()
1395+
Univariate Polynomial Ring in u over Skew Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5
14001396
sage: Q.parent() is S
1401-
True
1397+
False
1398+
1399+
However, in this case, convertion continues to work::
1400+
1401+
sage: S(u)
1402+
x^3
14021403
14031404
TESTS::
14041405
@@ -1412,13 +1413,15 @@ def center(self, name='z', names=None, coerce=False):
14121413
names = normalize_names(1, names)
14131414
center = PolynomialRing(self._constants, names)
14141415
embed = SkewPolynomialCenterInjection(center, self, self._embed_constants, self._order)
1415-
if coerce:
1416-
self.register_coercion(embed)
1417-
center.register_conversion(embed.section())
1418-
else:
1419-
try:
1416+
try:
1417+
if coerce:
1418+
self.register_coercion(embed)
1419+
else:
14201420
self.register_conversion(embed)
1421-
center.register_conversion(embed.section())
1422-
except AssertionError:
1423-
pass
1421+
except AssertionError:
1422+
pass
1423+
try:
1424+
center.register_conversion(embed.section())
1425+
except AssertionError:
1426+
pass
14241427
return center

0 commit comments

Comments
 (0)