[Python-ideas] Allow using symbols from Unicode block "Superscripts and Subscripts" in identifiers

Steven D'Aprano steve at pearwood.info
Sat May 3 11:05:24 CEST 2014


On Sat, May 03, 2014 at 06:38:21PM +1200, Greg Ewing wrote:
> Steven D'Aprano wrote:
> >Particularly for mathematically-focused code, I think it would be useful 
> >to be able to use identifiers like (say) σ² for variance,
> 
> Having σ² be a variable name could be confusing. To a
> mathematician, it's not a distinct variable, it's
> just σ ** 2.

Actually, not really. A better way of putting it is that the standard 
deviation is "just" the square root of σ². Variance comes first (it's 
defined from first principles), and then the standard deviation is 
defined by taking the square root.

But really, it doesn't matter which is derived from which. To a 
mathematician, x² is just as much a legitimate variable as x. One can 
say that f is a function of x² just as well as saying that it is a 
function of y, where y happens to equal x².

But regardless of philisophical differences regarding the nature of what 
is or isn't a variable, versus something derived from a variable, it 
simply is useful to have a one-to-one correspondence between variables 
in Python code and notation used in mathematics.

Is it useful enough to make up for the (minor) issues that others have 
already mentioned? I think so, but I will understand if others disagree. 
I think that the ability to distinguish between x² and x₂ can be 
important, and both x2 and x_2 are poor substitutes. (Of the two, I 
prefer x2.)

But I'm also aware that this is very dependent on the problem domain. I 
wouldn't use x² and x₂ outside of a mathematical context.



-- 
Steven


More information about the Python-ideas mailing list