#18758: Allow actions of a parent on itself
-------------------------------------+------------------------
Reporter: SimonKing | Owner:
Type: enhancement | Status: new
Priority: major | Milestone: sage-6.8
Component: coercion | Resolution:
Keywords: actions on itself | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: #18756 | Stopgaps:
-------------------------------------+------------------------
Description changed by SimonKing:
Old description:
> Currently, `ModuleElement.__mul__` raises an error when both elements
> have the same parent. Hence, in order to define a ring structure, one
> must not start with `ModuleElement`, which is bad, since sometimes the
> concrete structure only depends on the category (see
> !CombinatorialFreeModule).
>
> The approach to be implemented here: `ModuleElement.__mul__` and
> `RingElement.__mul__` should provide short-cuts in cases where there is
> an obvious way to be faster than calling the coercion model, and
> otherwise it is the job of the coercion model (NOT of
> `ModuleElement.__mul__`) to complain if the two elements come from the
> same parent without an action being defined.
>
> Hence, it should be possible to start with `ModuleElement` and get a ring
> structure on top of it by an appropriate action of the parent on itself.
>
> Moreover, it should be possible to define the actions using
> !ParentMethods in the category framework. I.e., `_get_action_` should be
> moved from Parent to Sets.!ParentMethods.
>
> This is motivated by the discussion on #18756
New description:
Currently, `ModuleElement.__mul__` raises an error when both elements have
the same parent. Hence, in order to define a ring structure, one must not
start with `ModuleElement`, which is bad, since sometimes the concrete
structure only depends on the category (see !CombinatorialFreeModule).
The approach to be implemented here: `ModuleElement.__mul__` and
`RingElement.__mul__` should provide short-cuts in cases where there is an
obvious way to be faster than calling the coercion model, and otherwise it
is the job of the coercion model (NOT of `ModuleElement.__mul__`) to
complain if the two elements come from the same parent without an action
being defined.
Hence, it should be possible to start with `ModuleElement` and get a ring
structure on top of it by an appropriate action of the parent on itself.
Here is an example that should be made work:
{{{
sage: from sage.categories.action import Action
sage: class RingStructure(Action):
....: def __init__(self, R):
....: Action.__init__(self, R, R, True, operator.mul)
....: def _call_(self, g, a):
....: return g._mul_(a)
....:
sage: from sage.structure.element import ModuleElement
sage: class MyElement(ModuleElement):
....: def __init__(self, P, L):
....: ModuleElement.__init__(self, P)
....: self.l = L
....: def _repr_(self):
....: return "<{}>".format(self.l)
....: def _add_(self, other):
....: return self.parent()(zip(self.l, other.l))
....: def _mul_(self, other):
....: return self.parent()(self.l+other.l)
....:
sage: class MyParent(Parent):
....: Element = MyElement
....: def _get_action_(self, S, op, self_on_left):
....: if S is self and op == operator.mul and self_on_left:
....: return RingStructure(self)
....:
sage: P = MyParent(category=Rings())
sage: l1 = P([1,2])
sage: l2 = P([3,4])
sage: l1+l2
<[(1, 3), (2, 4)]>
sage: l1*l2
<[1, 2, 3, 4]>
}}}
Moreover, it should be possible to define the actions using !ParentMethods
in the category framework. I.e., `_get_action_` should be moved from
Parent to Sets.!ParentMethods. This is why #18756 (where the whole idea
started) is a dependency.
More precisely: The above `RingStructure` (perhaps with some sanity test
similar to `sage.structure.coerce_action.ModuleAction`) should be defined
in sage.structure.coerce_actions` and used by
`Rings.ParentMethods._get_action_`.
--
--
Ticket URL: <http://trac.sagemath.org/ticket/18758#comment:2>
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/d/optout.