[Python-ideas] Left division operator

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Jul 18 07:46:21 CEST 2011


MRAB wrote:

> If there's a reverse division operator, then why not a reverse
> subtraction operator too?

I don't think the issue arises much with subtraction,
because it's uncommon to work with addition-like operations
that are not commutative.

As for modulo, it's not really the inverse of anything
in the way that / is the inverse of *.

If there were a reversed division operator, I would
probably have used it in a library I wrote recently for
coordinate transformations. In that domain it's
conventional to write the transformation on the left and
the thing being transformed on the right, and it's
natural to want to write an inverse transformation the
same way.

The solution I ended up with was to write the transformation
of V by the inverse of T as

   T.inv * V

where the inv attribute is calculated on demand and
cached. This corresponds somewhat to the way a mathematician
would write

      -1
    T    * V

-- 
Greg



More information about the Python-ideas mailing list