[Python-ideas] [RFC] draft PEP: Dedicated infix operators for matrix multiplication and matrix power

Bruce Leban bruce at leapyear.org
Tue Mar 18 05:14:03 CET 2014


On Sun, Mar 16, 2014 at 10:03 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> There are plenty of existing left-associative operators that could be
> used for that if Mike Bayer wanted (or could be convinced) to do so,
> so I don't see how that observation is relevant to the question of
> whether or not this particular proposal should be for a
> right-associative operator.
>

I knew I might get in trouble by giving such a specific example. My view is
that a new @ operator is "baggage free" in terms of implied semantics --
since it has defined semantics only for matrices.

To the extent that it has implied semantics of being multiplication-like, I
think it would be surprising that one multiplication operator is
left-associative and one is right-associative. Does @ have higher or lower
precedence than *? The draft PEP says @ is the same as * but it can't be if
it has opposite associativity. The interpretations of these two expressions
depends on the precedence:

A @ B * C
A * B @ C


Someone mentioned that APL is right-associative and has no
operator-precedence. Those two things are related. There's no operator
precedence because there are too many operators for everyone to remember
the exact order of precedence. Given that, all operators need to be left or
right associative. I don't know the reason for sure but I have heard that
one reason is that and given that monadic (unary) operators are right
associative, making all operators right associative means that you can
simply interpret an APL statement reading from right to left. I don't think
APL is the right model to look at.

--- Bruce
Learn how hackers think: http://j.mp/gruyere-security
https://www.linkedin.com/in/bruceleban
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140317/45429967/attachment.html>


More information about the Python-ideas mailing list