#14249: There should be no need to have _an_element_ implement to multiply 
elements
------------------------------+---------------------------------------------
       Reporter:  SimonKing   |         Owner:  robertwb        
           Type:  defect      |        Status:  needs_review    
       Priority:  major       |     Milestone:  sage-5.10       
      Component:  coercion    |    Resolution:                  
       Keywords:              |   Work issues:                  
Report Upstream:  N/A         |     Reviewers:  Travis Scrimshaw
        Authors:  Simon King  |     Merged in:                  
   Dependencies:  #14264      |      Stopgaps:                  
------------------------------+---------------------------------------------

Old description:

> 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.

New description:

 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.

 __Apply__

 * [attachment:trac_14249-coercion_without_an_element.patch]

--

Comment (by SimonKing):

 OK, the patches got folded.

 Apply trac_14249-coercion_without_an_element.patch

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14249#comment:12>
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to