# [Numpy-discussion] Possible new multiplication operators for Python

Grégory Lielens gregory.lielens@fft...
Tue Aug 19 02:49:14 CDT 2008

```On Mon, 2008-08-18 at 11:21 -0600, Charles R Harris wrote:

>
>
> Tim Hochberg proposed using the call operator for matrix
> multiplication, i.e.,
>
> A(B(C))
>
> Which has the advantage of using an existing operator. It looks like
> function composition, which isn't that far off the mark if matrices
> are looked at as mappings, but might take a bit of getting used to.
>
> Chuck
>

This was proposed at the time (It is mentioned in the PEP, but not in details).
Clever, but it leads to problems that, imho, makes the new operator
superior:
-It does not have the classic priority likes normal multiplication, but
the presence of parenthesis somewhat mitigates that. Associativity is
also not obvious, and mixing with scalar product does not always play
nice...
-It bares nothing in common with elementwise multiplication, which is
bothering if you enjoy orthogonality in language syntax (I do, it help
me memorize syntax tremendously), and looks like a (not pretty) trick,
especially when teaching the language to beginners

-It is not so easy to read:
A simple linear algebra formula like system solution could be written
x = (A.I)(b), which looks very nice....
[ A.I for lazy inversion of A, evaluated at assignation or as late as
possible, to allow for efficient implementation of A * x = b -> x =
A.I*b. This lazy operands were considered preferable to left and right
division à la Matlab at the time....]
Now  if you go back to an "heavy" formula from the PEP, it gives, using
classic * as matrix multiply and / as right-divide (x/Y = x * Y.I)
b = a.I - a.I * u / (c.I + v/a*u) * v / a
or with the tilde-operators
b = a.I - a.I ~* u / (c.I + v~/a~*u) ~* v ~/ a

Using __call__ as matmul:
b = a.I - ( (a.I)(u) / (c.I + (v/a)(u)) )(v) / a

Still quite nice, but more difficult to parse visually imho...
However, as most editors have parenthesis highlighting, it is worth
considering, notation can be abused but I agree that if you use spaces
and parenthesis cleverly, you can have some nice expressions...Pity the
original discussions are not available anymore, it would have been nice
to find the original drawbacks mentioned about __call__....

```

More information about the Numpy-discussion mailing list