Skip to content

Commit

Permalink
prefer coercion over action
Browse files Browse the repository at this point in the history
  • Loading branch information
mantepse committed May 1, 2024
1 parent c4363fc commit b9947d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sage/categories/pushout.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
lazy_import('sage.categories.commutative_rings', 'CommutativeRings')
lazy_import('sage.categories.groups', 'Groups')
lazy_import('sage.categories.objects', 'Objects')
lazy_import('sage.categories.rings', 'Rings', at_startup=True)
lazy_import('sage.categories.rings', 'Rings')

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

Expand Down
19 changes: 19 additions & 0 deletions src/sage/structure/coerce_actions.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,23 @@ cdef class ModuleAction(Action):
sage: 1/S.0
1/x
If there is a coercion from ``G`` to ``S``, we do not create
the module action of ``G`` on the pushout of ``G`` and ``S``::
sage: G = PolynomialRing(QQ, "x")
sage: S = PolynomialRing(MatrixSpace(QQ, 2), "x")
sage: G.gen() * S.gen()
[1 0]
[0 1]*x^2
Contrast the previous example with the following, where we
have no coercion from ``G`` to ``S``::
sage: S = PolynomialRing(MatrixSpace(QQ, 2), "y")
sage: G.gen() * S.gen()
[x 0]
[0 x]*y
"""
Action.__init__(self, G, S, not isinstance(self, RightModuleAction), operator.mul)
if not isinstance(G, Parent):
Expand All @@ -328,6 +345,8 @@ cdef class ModuleAction(Action):
# first we try the easy case of coercing G to the base ring of S
self.connecting = base._internal_coerce_map_from(G)
if self.connecting is None:
if S._internal_coerce_map_from(G) is not None:
raise CoercionException("Best viewed as standard coercion multiplication.")
# otherwise, we try and find a base extension
from sage.categories.pushout import pushout
# this may raise a type error, which we propagate
Expand Down

0 comments on commit b9947d2

Please sign in to comment.