[Python-ideas] Left division operator

Mike Graham mikegraham at gmail.com
Sun Jul 17 16:48:51 CEST 2011


On Sat, Jul 16, 2011 at 3:16 PM, Sturla Molden <sturla at molden.no> wrote:
> I was wondering if anyone else has felt the need for a leftward division
> operator in Python. That is, y\x in addition to x/y. Thus the operators:
>
>   y \ x
>   y \\ x

No, I haven't felt this need. As a former heavy Matlab user it crossed
my mind, but I don't really feel we're missing anything. The function
approach is just as clear and is more useful, in that different
problems call for different linear algebra solution routines. I am not
aware for any other good usage for such an operator.

> Why the statement "y\x" is different from "x/y":
>
> 1. Opposite order of evaluation: This is important if evaluating one of the
> operands has side-effects.

If we did get an \ operator, why not make it work like the rest of
Python? I don't see a compelling reason for this.

> 2. In linear algebra, (Y**-1)*X is in general not equal to X*(Y**-1). Matrix
> and vector algebra in fundamental to computer graphics and scientific
> computing.

Note that neither one of these are typically written as / or \ in math.

> 3. NumPy solves the lack of "\" operator by having a function
>  np.linalg.solve. But using it in matrix expressions has the effect of
> mixing Pythonic infix operators with a Lisp-like prefix operator.

This isn't a "Lisp-like prefix operator". Normal functions are
incredibly common in Python, in fact moreso than operators. They carry
the initial advantage that there can be many of them and that they
needn't be binary; this advantage is applicable to the problem at
hand, because I can do solve_triangular(x, y) or solve(x, y,
sym_pos=True, overwrite_a=True).

Mike



More information about the Python-ideas mailing list