[Python-ideas] π = math.pi

Brett Cannon brett at python.org
Sat Jun 3 13:45:43 EDT 2017


On Fri, 2 Jun 2017 at 15:56 Guido van Rossum <guido at python.org> wrote:

> I would love to show how easy it is to write
>
> from math import pi as π, gamma as Γ
>
> but I had to cheat by copying from the OP since I don't know how to type
> these (and even if you were to tell me how I'd forget tomorrow). So, I am
> still in favor of the rule "only ASCII in the stdlib".
>

Since this regularly comes up, why don't we add a note to the math module
that you can do the above import(s) to bind various mathematical constants
to their traditional symbol counterparts? The note can even start off with
something like "While Python's standard library only uses ASCII characters
to maximize ease of use and contribution, individuals are allowed to use
various Unicode characters for variable names." This would also help with
making sure people don't come back later and say, "why don't you just add
the constants to the module?"

-Brett


>
> On Fri, Jun 2, 2017 at 3:48 PM, Ivan Levkivskyi <levkivskyi at gmail.com>
> wrote:
>
>> On 2 June 2017 at 12:17, Giampaolo Rodola' <g.rodola at gmail.com> wrote:
>>
>>> On Thu, Jun 1, 2017 at 8:47 AM, Serhiy Storchaka <storchaka at gmail.com>
>>> wrote:
>>>
>>>> What you are think about adding Unicode aliases for some mathematic
>>>> names in the math module? ;-)
>>>>
>>>> math.π = math.pi
>>>> math.τ = math.tau
>>>> math.Γ = math.gamma
>>>> math.ℯ = math.e
>>>>
>>>> Unfortunately we can't use ∞, ∑ and √ as identifiers. :-(
>>>>
>>>> [...]
>>> * duplicated aliases might make sense if they add readability; in this
>>> case they don't unless (maybe) you have a mathematical background. I can
>>> infer what "math.gamma" stands for but not being a mathematician math.Γ
>>> makes absolutely zero sense to me.
>>>
>>>
>> There is a significant number of scientific Python programmers (21%
>> according to PyCharm 2016), so it is not that rare to meet someone who
>> knows what is Gamma function.
>> And for many of them π is much more readable than np.pi. Also there is
>> another problem, confusion between Gamma function and Euler–Mascheroni
>> constant, the first one is Γ,
>> the second one is γ (perfectly opposite to PEP 8 capitalization rules
>> :-), while both of them are frequently denoted as just gamma (in particular
>> math.gamma follows the PEP8 rules,
>> but is counter-intuitive for most scientist).
>>
>> All that said, I agree that these problems are easily solved by a custom
>> import from. Still there is something in (or related to?) this proposal
>> I think is worth considering: Can we also allow identifiers like ∫ or √.
>> This will make many expressions more similar to usual TeX,
>> plus it will be useful for projects like SymPy.
>>
>> --
>> Ivan
>>
>>
>>
>> _______________________________________________
>> 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/
>>
>>
>
>
> --
> --Guido van Rossum (python.org/~guido)
> _______________________________________________
> 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/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170603/2453e68b/attachment-0001.html>


More information about the Python-ideas mailing list