#18756: Use coerce actions in the category framework
-------------------------------------------------+-------------------------
       Reporter:  SimonKing                      |        Owner:
           Type:  defect                         |       Status:  new
       Priority:  major                          |    Milestone:  sage-6.8
      Component:  coercion                       |   Resolution:
       Keywords:  cython, coercion, actions,     |    Merged in:
  categories                                     |    Reviewers:
        Authors:                                 |  Work issues:
Report Upstream:  N/A                            |       Commit:
         Branch:                                 |     Stopgaps:
   Dependencies:                                 |
-------------------------------------------------+-------------------------
Changes (by SimonKing):

 * component:  algebra => coercion
 * branch:  u/SimonKing/combinatorial_free_module_cython_coercion =>


Comment:

 The commit that I just pushed moves `CombinatorialFreeModule` to Cython
 and lets it use `RingElement` and `_l/rmul_` instead of the current
 approach to work around the coercion framework.

 Note that an action only depends on the parents involved and is cached.
 Hence, it is better faster to invoke the category framework to use the
 action to do a multiplication, than to let `__mul__` decide on the
 implementation of multiplication in each single instance. Hence, we should
 NOT do
 {{{
 #!python
 class Modules:
     class ElementMethods:
         def __mul__(self, other):
             if self.base_ring().has_coerce_map_from(parent(other)):
                 # Bad case-by-case behaviour
                 return self._mul_(other)
             return coercion_model.bin_op(self, other, operator.mul)
 }}}
 and its counterpart in `Magmas.ElementMethods`. Instead, one should have a
 `ParentMethod` returning an action.

 However, my plan is to first sanitise the code of `[Ring/Module]Element`:
 1. A parent should be able to provide an action on ANY parent, including
 itself.
 2. The possibility to use any action should be implemented on the level of
 `Element.__mul__` (similarly `Element.__add__` etc).
 3. The only thing that `ModuleElement.__mul__` and `RingElement.__mul__`
 should contribute is a short-cut. That's basically what is already done:
 `ModuleElement.__mul__` treats python int in a special way, since I guess
 the typecheck involved is faster than calling the `coercion_model`; and
 `RingElement.__mul__` deals with the special case that the two elements
 have identical parents, which again is faster than calling the
 `coercion_model`.

--
Ticket URL: <http://trac.sagemath.org/ticket/18756#comment:13>
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.

Reply via email to