#18756: Use cython and coercion for CombinatorialFreeModule
-------------------------------------------------+-------------------------
Reporter: SimonKing | Owner:
Type: defect | Status: new
Priority: major | Milestone: sage-6.8
Component: algebra | Resolution:
Keywords: CombinatorialFreeModule, | Merged in:
cython, coercion | Reviewers:
Authors: | Work issues:
Report Upstream: N/A | Commit:
Branch: | Stopgaps:
Dependencies: |
-------------------------------------------------+-------------------------
Comment (by SimonKing):
Sage provides the possibility to define arbitrary actions. See
sage.structure.coerce_actions.
As much as I can see, the only action that currently can not be defined is
an action of a parent on itself. I suggest to change it, as follows.
- `RingElement.__mul__` should stay as it is. Since we have a ring
element, we can assume that there is a multiplication among elements of
the same parent, which is to be implemented with `_mul_`.
- `ModuleElement.__mul__` currently does the following:
{{{
#!python
def __mul__(left, right):
if PyInt_CheckExact(right):
return (<ModuleElement>left)._mul_long(PyInt_AS_LONG(right))
if PyInt_CheckExact(left):
return (<ModuleElement>right)._mul_long(PyInt_AS_LONG(left))
if have_same_parent_c(left, right):
raise TypeError(arith_error_message(left, right, mul))
return coercion_model.bin_op(left, right, mul)
}}}
Apparently, the line "if have_same_parent_c..." is to break a recursion.
Instead, I suggest that `coercion_model.bin_op` should be changed, so that
the parent has the possibility to define an action ON ITSELF (using
`Parent._get_action_`).
The first point is that it would be easy to implement `_get_action_` as a
parent method of a category:
- The parent method could first test if it inherits an action (e.g. an
`sage.structure.coerce_action.LeftModuleAction` in the case of a module),
and if not then it should see if an action of the parent on itself may be
implemented using product_on_basis and friends.
The second point is:
- The action could be implemented in Cython, which is already the case for
`sage.structure.coerce_action.LeftModuleAction`.
The third point is:
- The approach is very flexible. _get_action_ can return an action that
relies on product_on_basis or that relies on _mul_ or on _lmul_ or on
_my_fancy_multiplication_. Hence, there would be no need to override
`_mul_` just to make things work. There are other paths to achieve the
same aim.
--
Ticket URL: <http://trac.sagemath.org/ticket/18756#comment:9>
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.