Skip to content

Commit 339a072

Browse files
author
Release Manager
committed
sagemathgh-37916: structure/coerce actions We modify `ModuleAction` to prefer coercion of the base ring over creating an action. More precisely, before this branch, we have ``` sage: G = PolynomialRing(QQ, "x") sage: S = PolynomialRing(MatrixSpace(QQ, 2), "x") sage: G.gen() * S.gen() [x 0] [0 x]*x ``` instead of ``` [1 0] [0 1]*x^2 ``` and ``` sage: G = PolynomialRing(QQ, "x") sage: S = PolynomialRing(InfinitePolynomialRing(QQ, "a"), "x") sage: G.gen() * S.an_element() x*x ``` instead of ``` x^2 ``` which is at least surprising. In the end, this is needed to make sagemath#37033 work. Authors: @tscrim and @mantepse. URL: sagemath#37916 Reported by: Martin Rubey Reviewer(s): Travis Scrimshaw
2 parents 04f4b17 + b9947d2 commit 339a072

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/sage/categories/pushout.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
lazy_import('sage.categories.commutative_rings', 'CommutativeRings')
3636
lazy_import('sage.categories.groups', 'Groups')
3737
lazy_import('sage.categories.objects', 'Objects')
38-
lazy_import('sage.categories.rings', 'Rings', at_startup=True)
38+
lazy_import('sage.categories.rings', 'Rings')
3939

4040
# TODO, think through the rankings, and override pushout where necessary.
4141

src/sage/structure/coerce_actions.pyx

+19
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,23 @@ cdef class ModuleAction(Action):
315315
sage: 1/S.0
316316
1/x
317317
318+
If there is a coercion from ``G`` to ``S``, we do not create
319+
the module action of ``G`` on the pushout of ``G`` and ``S``::
320+
321+
sage: G = PolynomialRing(QQ, "x")
322+
sage: S = PolynomialRing(MatrixSpace(QQ, 2), "x")
323+
sage: G.gen() * S.gen()
324+
[1 0]
325+
[0 1]*x^2
326+
327+
Contrast the previous example with the following, where we
328+
have no coercion from ``G`` to ``S``::
329+
330+
sage: S = PolynomialRing(MatrixSpace(QQ, 2), "y")
331+
sage: G.gen() * S.gen()
332+
[x 0]
333+
[0 x]*y
334+
318335
"""
319336
Action.__init__(self, G, S, not isinstance(self, RightModuleAction), operator.mul)
320337
if not isinstance(G, Parent):
@@ -330,6 +347,8 @@ cdef class ModuleAction(Action):
330347
# first we try the easy case of coercing G to the base ring of S
331348
self.connecting = base._internal_coerce_map_from(G)
332349
if self.connecting is None:
350+
if S._internal_coerce_map_from(G) is not None:
351+
raise CoercionException("Best viewed as standard coercion multiplication.")
333352
# otherwise, we try and find a base extension
334353
from sage.categories.pushout import pushout
335354
# this may raise a type error, which we propagate

0 commit comments

Comments
 (0)