[Python-ideas] Why operators are useful

Rémi Lapeyre remi.lapeyre at henki.fr
Sat Mar 16 08:57:09 EDT 2019

Le 16 mars 2019 à 10:02:31, Greg Ewing
(greg.ewing at canterbury.ac.nz(mailto:greg.ewing at canterbury.ac.nz)) a

> Rémi Lapeyre wrote:
> > I think this omit a very important property of
> > mathematic equations thought, maths is a very strongly typed language
> > which can be a significant improvement for readability.
> Python is very strongly typed too, so I don't really see how
> maths is different.

Sorry, this should have read « maths is a statically typed language ».

For example, in Python I can write:

def inverse(x):
	return x ** (-1)

But this would never be accepted in maths, I should say one of

   R -> R
f: x -> x ** (-1)

   R+* -> R
f: x   -> x ** (-1)

   [1; +oo[ -> R
f: x        -> x ** (-1)

   GLn(K) -> GLn(K)
f: x      -> x ** (-1)

And in all those examples, ** would have meant something very
different and the resulting objects f are very different.

For example, the third one is Lipschitz continuous but not the
first. On the other hand, I know nothing regarding the inverse
Function in Python.

Knowing nothing about `inverse` means that every time I use it
i must determine what it means in the given context.

> > For example, a
> > mathematician working within the space of linear maps over a vector
> > space will easily recognize the meaning of every symbol in:
> >
> > f(a * x + y) = a * f(x) + f(y)
> Yes, but he has to remember what types are associated with
> the variables -- nothing at their point of use indicates that.
> Likewise, the reader of a Python program has to remember what
> type of object each name is expected to be bound to. If he
> can remember that, he will know what all the operators do.

The overhead to track the associated type for a given name in maths
is far lower since it is a functional language. In maths, I can just
make a mental note of it and be done with it; in Python, you can
never be sure the type of the binded object did not change unexpectedly.

> --
> Greg
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

More information about the Python-ideas mailing list