Time we switched to unicode? (was Explanation of this Python language feature?)

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Mar 25 16:18:56 CET 2014

On Tue, 25 Mar 2014 05:09:20 -0700, Rustom Mody wrote:

> Two completely separate questions
> 1. Symbols outside of US-104-keyboard/ASCII used for python
>    functions/constants
> 2. Non-linear math notation
> It goes back not just to the first programming languages but to Turing's
> paper that what a mathematician can do on 2-d paper can be done on a 1-d
> 'tape'. IOW conflating 1 and 2 is not even a poor strawman argument --
> Its only 1 that anyone is talking about.

Not so. Mark Harris said:

    But what if python had a math symbols extension so that universal
    mathematics could be written the way we do it on a black|board, 
    er, I mean white|board?

I think that's pretty explicit that he's talking about writing 
mathematical code the way mathematicians write mathematics.

Antoon Pardon referred to borrowing the symbols used in mathematics. But 
the point is that the symbols come with notation: - (minus) can be prefix 
unary operator or a infix binary operator. ∑ (summation) is a quaternary 
operator, it takes four arguments: a variable name, a lower limit, an 
upper limit, and an expression. To be true to the mathematical notation, 
we ought to write it the way mathematicians do.

The thing is, we can't just create a ∑ function, because it doesn't work 
the way the summation operator works. The problem is that we would want 
syntactic support, so we could write something like this:

    p = 2
    ∑(n, 1, 10, n**p)

This cannot be an ordinary function, because if it were, the n**p 
expression would be evaluated before passing the result to the function. 
We want it to delay evaluation, like a list comp:

    [n**p for n in range(1, 11)]

the expression n**p gets evaluated inside the list comp. That cannot be 
written as a function either:

    list_comp(n**p, n, range(1, 11))

Mark's idea of a maths blackboard is not ridiculous. That's what 
Mathematica does. To enter a sum like the above in Mathematica, you can 

    ESC sum ESC Ctrl+$ n=1 Ctrl+% 10 Ctrl+Space n^p

to give you the summation 

    ∑  n**p

Obviously this requires a custom editor.


But Mathematica is a specialist system for doing mathematics, not a 
general purpose language like Python. Of course one could *write* a 
Mathematica-like system in Python, and I expect that Sage may even have 
something like this (if it doesn't, it could) but one shouldn't hammer 
the specialised round peg of complex mathematical notation into the 
square peg of a general purpose programming language.

Steven D'Aprano

More information about the Python-list mailing list