#28966 closed enhancement (fixed)
Provide unicode aliases for some globals in Python 3
Reported by:  embray  Owned by:  

Priority:  major  Milestone:  sage9.2 
Component:  user interface  Keywords:  
Cc:  ghmwageringel, tscrim, nthiery  Merged in:  
Authors:  Matthias Koeppe  Reviewers:  Markus Wageringel 
Report Upstream:  N/A  Work issues:  
Branch:  62de65d (Commits, GitHub, GitLab)  Commit:  
Dependencies:  #30106  Stopgaps: 
Description (last modified by )
This is something that's been discussed before but I don't think there's a ticket for it.
Python 3 allows unicode wordconstituent characters to be used in identifiers, https://docs.python.org/3/reference/lexical_analysis.html#identifiers, subject to NFKC normalization. So we can easily provide unicode aliases for some common functions and constants named and denoted by Greek letters.
In Python 3 / IPython it is also possible to do tabcompletion for many unicode characters: https://ipython.readthedocs.io/en/stable/api/generated/IPython.core.completer.html#latexandunicodecompletion
(This list can easily be expanded by modifying the dict in IPython.completer.latex_symbols
.)
sage: π pi sage: _.n() 3.14159265358979 sage: sin(π) 0 sage: σ Function that adds up (kth powers of) the divisors of n sage: Γ <function gamma at 0x7ff3f051a710> sage: ψ <function psi at 0x7ff3f0531320> sage: ζ zeta sage: ζ(1) 1/12
Change History (21)
comment:1 Changed 13 months ago by
 Milestone changed from sage9.1 to sage9.2
comment:2 Changed 10 months ago by
 Cc ghmwageringel added
 Dependencies set to #30106
comment:3 in reply to: ↑ description Changed 10 months ago by
Replying to embray:
ℯ = e 𝒾 = I ℤ = ZZ ℚ = QQ
Due to identifier normalization, these four identifiers are actually the same as their ASCII equivalents. For example:
sage: Q = 42 sage: ℚ 42
comment:4 Changed 9 months ago by
 Description modified (diff)
comment:5 Changed 9 months ago by
 Branch set to u/mkoeppe/provide_unicode_aliases_for_some_globals_in_python_3
comment:6 Changed 9 months ago by
 Commit set to 11aeb1542b40a8703f75f5ee38915cd91488d895
 Description modified (diff)
 Status changed from new to needs_review
New commits:
11aeb15  Add globals σ, Γ, ψ, ζ, π

comment:7 Changed 9 months ago by
 Cc tscrim added
comment:8 Changed 9 months ago by
 Cc nthiery added
comment:9 Changed 9 months ago by
 Reviewers set to Markus Wageringel
 Status changed from needs_review to needs_work
There is one failing doctest. Otherwise this looks good to me.
comment:10 Changed 9 months ago by
Interactively, the failing test fails even harder:
sage: import_statements(pi) TypeError: <class 'object'> is a builtin class
comment:11 followup: ↓ 16 Changed 9 months ago by
This seems to be related to https://groups.google.com/forum/#!topic/sagedevel/7qelSgBOL0.
comment:12 Changed 9 months ago by
 Commit changed from 11aeb1542b40a8703f75f5ee38915cd91488d895 to 3d602ca0a27ebf124059423bc834415dcc86cc39
Branch pushed to git repo; I updated commit sha1. New commits:
3d602ca  find_object_modules: Ignore errors from modules where getsource fails

comment:13 Changed 9 months ago by
Perhaps this fix needs to be pushed into sageinspect
comment:14 Changed 9 months ago by
 Commit changed from 3d602ca0a27ebf124059423bc834415dcc86cc39 to 62de65d207690234003087e9ef39ef4a46e53ba9
comment:15 Changed 9 months ago by
 Status changed from needs_work to needs_review
comment:16 in reply to: ↑ 11 ; followup: ↓ 17 Changed 9 months ago by
Replying to ghmwageringel:
This seems to be related to https://groups.google.com/forum/#!topic/sagedevel/7qelSgBOL0.
I'll not work on this one
comment:17 in reply to: ↑ 16 Changed 9 months ago by
 Status changed from needs_review to positive_review
Replying to mkoeppe:
I'll not work on this one
This is an upstream issue really.
This looks good to me now, so I am setting this to positive.
comment:18 Changed 9 months ago by
Thank you.
comment:19 Changed 9 months ago by
 Branch changed from u/mkoeppe/provide_unicode_aliases_for_some_globals_in_python_3 to 62de65d207690234003087e9ef39ef4a46e53ba9
 Resolution set to fixed
 Status changed from positive_review to closed
comment:20 Changed 9 months ago by
 Commit 62de65d207690234003087e9ef39ef4a46e53ba9 deleted
Oh cool, I didn't know this was finally implemented ^^
comment:21 Changed 9 months ago by
I think this should probably be mentioned in the documentation though.
Batch modifying tickets that will likely not be ready for 9.1, based on a review of the ticket title, branch/review status, and last modification date.