On Tue, Jul 27, 2010 at 12:50 AM, Simon King <simon.k...@nuigalway.ie> wrote:
> Hi Drenwal,
>
> On 25 Jul., 10:52, drenwal <dren...@free.fr> wrote:
>> But, I would prefer to use a more mathematical notation, like Y[k] or
>> y...@k or whatever non already used symbol instead of Ac(y,k).
>
> As Johannes has pointed out, Y[k] is already used, so, this might not
> be what you want. But, if it is, overwrite __getitem__ of matrices
> (this is the method that Python expects if you do Y[...]).
> '^' is also used; if you still want to use it, overwrite __pow__.
>
>> How is it possible to do that?
>
> I don't know if/how '@' can be made use of. Usually, it seems that @
> indicates that a so-called decorator is being used.
>
> Talking about generators: There is a decorator that allows to define a
> custom infix operator (see
> http://www.sagemath.org/doc/reference/sage/misc/misc.html#sage.misc.misc.infix_operator).
> This might be what you were looking for, because it allows to create
> new operator names.
>
> Example:
>  sage: from sage.all import infix_operator
>  sage: @infix_operator('multiply')
>  ....: def foo(a,b):
>  ....:     return '%s acts from the right on %s'%(b,a)
>  ....:
>  sage: 5 *foo* 2
>  '2 acts from the right on 5'
>
> Of course, in your case, it would be
>   return b.transpose()*a*b

This is exactly what I was going to suggest. This is how we handle the
backslash operator for linear system solving:

http://hg.sagemath.org/sage-main/file/426be7b253ad/sage/misc/preparser.py#l1310

- Robert

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to