Coerce actions
Bases: sage.structure.coerce_actions.GenericAction
Class for actions defined via the _act_on_ method.
Bases: sage.structure.coerce_actions.GenericAction
Class for actions defined via the _acted_upon_ method.
Bases: sage.categories.action.Action
TESTS:
sage: sage.structure.coerce_actions.ActedUponAction(MatrixSpace(ZZ, 2), Cusps, True)
Left action by Full MatrixSpace of 2 by 2 dense matrices over Integer Ring on Set P^1(QQ) of all cusps
sage: sage.structure.coerce_actions.GenericAction(QQ, Zmod(6), True)
Traceback (most recent call last):
...
NotImplementedError: Action not implemented.
This will break if we tried to use it:
sage: sage.structure.coerce_actions.GenericAction(QQ, Zmod(6), True, check=False)
Left action by Rational Field on Ring of integers modulo 6
Returns the “codomain” of this action, i.e. the Parent in which the result elements live. Typically, this should be the same as the acted upon set.
EXAMPLES:
sage: A = sage.structure.coerce_actions.ActedUponAction(MatrixSpace(ZZ, 2), Cusps, True)
sage: A.codomain()
Set P^1(QQ) of all cusps
sage: A = sage.structure.coerce_actions.ActOnAction(SymmetricGroup(3), QQ['x,y,z'], False)
sage: A.codomain()
Multivariate Polynomial Ring in x, y, z over Rational Field
Bases: sage.categories.action.Action
This class implements the action via
repeated doubling.
Both addition and negation must be defined on the set .
EXAMPLES:
sage: from sage.structure.coerce_actions import IntegerMulAction
sage: R.<x> = QQ['x']
sage: act = IntegerMulAction(ZZ, R)
sage: act(5, x)
5*x
sage: act(0, x)
0
sage: act(-3, x-1)
-3*x + 3
Bases: sage.structure.coerce_actions.ModuleAction
This creates an action of an element of a module by an element of its base ring. The simplest example to keep in mind is R acting on the polynomial ring R[x].
The actual action is implemented by the _rmul_ or _lmul_ function on its elements. We must, however, be very particular about what we feed into these functions because they operate under the assumption that the inputs lie exactly in the base ring and may segfault otherwise.
Thus we handle all possible base extensions manually here. This is an abstract class, one must actually instantiate a LeftModuleAction or a RightModuleAction
EXAMPLES:
sage: from sage.structure.coerce_actions import LeftModuleAction
sage: LeftModuleAction(ZZ, ZZ['x'])
Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Integer Ring
sage: LeftModuleAction(ZZ, QQ['x'])
Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Rational Field
sage: LeftModuleAction(QQ, ZZ['x'])
Left scalar multiplication by Rational Field on Univariate Polynomial Ring in x over Integer Ring
sage: LeftModuleAction(QQ, ZZ['x']['y'])
Left scalar multiplication by Rational Field on Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Integer Ring
The following tests against a problem that was relevant during work on trac ticket #9944:
sage: R.<x> = PolynomialRing(ZZ)
sage: S.<x> = PolynomialRing(ZZ, sparse=True)
sage: 1/R.0
1/x
sage: 1/S.0
1/x
Bases: sage.categories.action.Action
This creates an action of an element of a module by an element of its base ring. The simplest example to keep in mind is R acting on the polynomial ring R[x].
The actual action is implemented by the _rmul_ or _lmul_ function on its elements. We must, however, be very particular about what we feed into these functions because they operate under the assumption that the inputs lie exactly in the base ring and may segfault otherwise.
Thus we handle all possible base extensions manually here. This is an abstract class, one must actually instantiate a LeftModuleAction or a RightModuleAction
EXAMPLES:
sage: from sage.structure.coerce_actions import LeftModuleAction
sage: LeftModuleAction(ZZ, ZZ['x'])
Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Integer Ring
sage: LeftModuleAction(ZZ, QQ['x'])
Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Rational Field
sage: LeftModuleAction(QQ, ZZ['x'])
Left scalar multiplication by Rational Field on Univariate Polynomial Ring in x over Integer Ring
sage: LeftModuleAction(QQ, ZZ['x']['y'])
Left scalar multiplication by Rational Field on Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Integer Ring
The following tests against a problem that was relevant during work on trac ticket #9944:
sage: R.<x> = PolynomialRing(ZZ)
sage: S.<x> = PolynomialRing(ZZ, sparse=True)
sage: 1/R.0
1/x
sage: 1/S.0
1/x
The codomain of self, which may or may not be equal to the domain.
EXAMPLES:
sage: from sage.structure.coerce_actions import LeftModuleAction
sage: A = LeftModuleAction(QQ, ZZ['x,y,z'])
sage: A.codomain()
Multivariate Polynomial Ring in x, y, z over Rational Field
The domain of self, which is the module that is being acted on.
EXAMPLES:
sage: from sage.structure.coerce_actions import LeftModuleAction
sage: A = LeftModuleAction(QQ, ZZ['x,y,z'])
sage: A.domain()
Multivariate Polynomial Ring in x, y, z over Integer Ring
Bases: sage.structure.coerce_actions.ModuleAction
This creates an action of an element of a module by an element of its base ring. The simplest example to keep in mind is R acting on the polynomial ring R[x].
The actual action is implemented by the _rmul_ or _lmul_ function on its elements. We must, however, be very particular about what we feed into these functions because they operate under the assumption that the inputs lie exactly in the base ring and may segfault otherwise.
Thus we handle all possible base extensions manually here. This is an abstract class, one must actually instantiate a LeftModuleAction or a RightModuleAction
EXAMPLES:
sage: from sage.structure.coerce_actions import LeftModuleAction
sage: LeftModuleAction(ZZ, ZZ['x'])
Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Integer Ring
sage: LeftModuleAction(ZZ, QQ['x'])
Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Rational Field
sage: LeftModuleAction(QQ, ZZ['x'])
Left scalar multiplication by Rational Field on Univariate Polynomial Ring in x over Integer Ring
sage: LeftModuleAction(QQ, ZZ['x']['y'])
Left scalar multiplication by Rational Field on Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Integer Ring
The following tests against a problem that was relevant during work on trac ticket #9944:
sage: R.<x> = PolynomialRing(ZZ)
sage: S.<x> = PolynomialRing(ZZ, sparse=True)
sage: 1/R.0
1/x
sage: 1/S.0
1/x
Returns an action of X on Y or Y on X as defined by elements X, if any.
EXAMPLES:
sage: from sage.structure.coerce_actions import detect_element_action
sage: detect_element_action(ZZ['x'], ZZ, False)
Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Integer Ring
sage: detect_element_action(ZZ['x'], QQ, True)
Right scalar multiplication by Rational Field on Univariate Polynomial Ring in x over Integer Ring
sage: detect_element_action(Cusps, MatrixSpace(ZZ, 2), False)
Left action by Full MatrixSpace of 2 by 2 dense matrices over Integer Ring on Set P^1(QQ) of all cusps
sage: detect_element_action(Cusps, MatrixSpace(ZZ, 2), True),
(None,)
sage: detect_element_action(ZZ, QQ, True),
(None,)
TESTS:
This test checks that the issue in Trac #7718 has been fixed:
sage: class MyParent(Parent):
... def an_element(self):
... pass
...
sage: A = MyParent()
sage: detect_element_action(A, ZZ, True)
Traceback (most recent call last):
...
RuntimeError: an_element() for <class '__main__.MyParent'> returned None