Discussion: new operators for numerical computation

Tim Hochberg tim.hochberg at ieee.org
Fri Jul 21 21:28:52 EDT 2000


At this point there seems to be main proposals. There are variations
on these basic themes, but these two capture the main points:

------------------------------------------------------------------------

Proposal one, which for lack of a better name I'll call Huaiyu's proposal:

New Operators: .+, .-, ./, .*

NumPy and MatPy would have reversed syntax: the new would operators
correspond to element operations in MatPy and matrix operators in
NumPy.

There is similar syntax proposal that subsitutes @ for '.'. Although it
avoides the last disadvantage (below), it seems to have less
support. Perhaps because it seems hard to parse visually since @ looks
more like a symbol than an operator (in my subjective opinion).

Advantages:	Similarity to MatLab syntax.
Disadvantages:	Reversed syntax.
		Essentially precludes eventual unification of NumPy and MatPy.
		5.+A probably won't confuse the parser, but it may confuse me.

-----------------------------------------------------------------------

Proposal two, which for lack of a better name I'll call Konrad's proposal:

New Operators: (+), (-), (/), (*)[outer], (.)[dot], (|)[solve], (^)[power] 

NumPy and MatPy would have that same syntax: the new operators correspond to
matrix operations in both MatPy and matrix operators in NumPy.

There are some other possibilities for operators here. In particular
(**) for power. However if we're already abusing bitwise-or for solve,
why not abuse bitwise-xor for power?

It's possible to imagine this syntax with the operators reversed
between NumPy and MatPy, but it would be a waste: (|), (.), and (^)
don't make good elementwise symbols, and MatPy would still be stuck
without a symbol for outer and solve.

Advantages:	Syntax for both inner, outer, and solve.
		Unifies NumPy and MatPy syntax now.			
Disadvantages:	Unfamiliar Syntax for MatLab users.

-----------------------------------------------------------------------

Given these two basic proposals, I strongly prefer Konrad's. I think
the syntax is more evocative of matrix operations. From the tone of
other post on this syntax, this syntax seems to be accepted, perhaps
even prefered, by most most people. I also am strongly a proponent of
the syntax of various Numeric packages being a similar as possible. In
this case NumPy and MatPy.

It's not an option for NumPy or some successor to adopt the MatPy
syntax. Not only is there a large NumPy codebase, but in NumPy the
elementwise operations ^,|, & and % are important. In order for a
syntax such as that proposed in Huaiyu's proposal for MatPy to be
adopted, an additional 4 (or more I may have missed something)
operators would need to be adopted. I don't think this is feasible,
particularly since the same effect (and more) could be achieved in
Konrad's proposal without the extra operators.

That's my opinion and I'm sticking to it, at least till I come up with
a different one.

-tim



More information about the Python-list mailing list