[Python-ideas] [RFC] draft PEP: Dedicated infix operators for matrix multiplication and matrix power
Greg Ewing
greg.ewing at canterbury.ac.nz
Sat Mar 15 23:31:49 CET 2014
Antoine Pitrou wrote:
> It can just as well represent "acting" on v with (A @ B @ C).
Yes, but if you ask what A @ B @ C means as an operator,
it means "the same thing as acting with C, then B, then A."
The fact that evaluating it right-to-left also happens to
be more efficient in some cases means that there are both
conceptual *and* practical reasons for making @ right
associative.
I was just trying to point out that efficiency is not the
*only* reason to consider this.
There's a counter-argument as well -- it's only more
efficient if the rightmost operand is just a single vector
or a small enough array of vectors. Otherwise, it's more
efficient to calculate a combined operator and then
apply that. So the question would be whether the small
case is common enough in practice to be worth having an
unusual associativity.
A data point from another language, for what it's worth:
In APL, *all* operators are right-associative. I'm not
sure what the reason for that choice was, but it may
result from a similar line of reasoning around how
mathematicians think about things.
--
Greg
More information about the Python-ideas
mailing list