Hi David,

On 2013-07-16, David Kohel <drko...@gmail.com> wrote:
> Defining the (left or right) action by * would probably be a 
> nightmare with the coercion model, since it is handled as 
> a symmetric operator. 

Is this really so?

There is stuff in sage.structure.coerce, for example methods 
R.get_action(S,operator.mul),
which can be overloaded using R._get_action_, where you can also decide on the
side from which S acts.

Hence, if you want to let S act on R from the left by multiplication, you could
simply let S._get_action_(R, operator.mul, True) return an action, and
if you want to let S act on R from the right by multiplication, you
could let S._get_action_(R, operator.mul, False) return an action.

Here, "action" means something like the stuff in
sage.structure.coerce_acitons.

Let's try an example:
  sage: from sage.structure.coerce_actions import GenericAction
  sage: class MyAction(GenericAction):
  ....:     def _call_(self, x, y):
  ....:         if self.is_left():
  ....:             return x.left_action(y)
  ....:         return y.right_action(x)
  ....:     
  sage: from sage.structure.element import Element
  sage: class MyElement(Element):
  ....:     def __init__(self, s, parent=None):
  ....:         self.s = s
  ....:         Element.__init__(self, parent)
  ....:     def left_action(self, n):
  ....:         return self.__class__(self.s+repr(n), self.parent())
  ....:     def right_action(self, n):
  ....:         return self.__class__(self.s*n, self.parent())
  ....:     
  sage: class MyParent(Parent):
  ....:     Element = MyElement
  ....:     def _get_action_(self, S, op, self_is_left):
  ....:         if op is operator.mul:
  ....:             return MyAction(self, S, self_is_left, check=False)
  ....:     def _element_constructor_(self, s):
  ....:         return self.element_class(s, self)
  ....:     
  sage: P = MyParent(category=Objects())
  sage: a = P('hi')
  sage: a.s
  'hi'
  sage: b = a*5
  sage: b.s
  'hi5'
  sage: c = 3*a
  sage: c.s
  'hihihi'

So, this should show how to implement left and right actions.

Of course, the mathematical property of being an action must be ensured
by a correct implementation of the action.

In particular, note that technically I have implemented an action of
MyParent on ZZ, but in fact I did so in order to get two different
actions of ZZ on MyParent.

Best regards,
Simon


-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to