There should be no need to have _an_element_ to multiply elements
|Reported by:||SimonKing||Owned by:||robertwb|
|Authors:||Simon King||Reviewers:||Travis Scrimshaw|
|Report Upstream:||N/A||Work issues:|
Description (last modified by )
We currently have
sage: from sage.structure.element import ModuleElement sage: class MyElement(ModuleElement): ....: def __init__(self, x, y, parent=None): ....: ModuleElement.__init__(self, parent) ....: def _mul_(self, other): ....: return self ....: def _rmul_(self, other): ....: return self ....: def _lmul_(self, other): ....: return self ....: sage: class MyParent(Parent): ....: Element = MyElement ....: sage: P = MyParent(category=Rings()) sage: P(1,2) Generic element of a structure sage: a = _ sage: a*2 Traceback (most recent call last): ... NotImplementedError: please implement _an_element_ for <class '__main__.MyParent_with_category'>
I find this very annoying.
The background is that the coercion model tries to get a multiplication action, namely
RightModuleAction. During initialisation of the module action, some sanity tests are performed. In particular, an element of the acting parent and the acted-upon set are taken and the action called on these two elements.
Problem: Where to get the two elements from? Currently, they are gotten from the method
an_element(), which in turn relies on
_an_element_() being implemented if the default implementation is not good enough (which is the case in the example above).
But normally, we do not want to have the
RightModuleAction just out of the blue: Typically (in the example above, at least), we want to create it during the first multiplication. And in that moment we do have two elements.
So, I propose to make it possible to pass the two elements being multiplied to the constructor of
Left/RightModuleAction, and let
an_element() be called only if no element is passed.
Change History (19)
Changed 4 years ago by
Changed 4 years ago by
comment:17 Changed 4 years ago by
- Merged in set to sage-5.10.rc0
- Resolution set to fixed
- Status changed from positive_review to closed
- Summary changed from There should be no need to have _an_element_ implement to multiply elements to There should be no need to have _an_element_ to multiply elements