Opened 11 months ago

Closed 3 months ago

Last modified 3 months ago

#28966 closed enhancement (fixed)

Provide unicode aliases for some globals in Python 3

Reported by: embray Owned by:
Priority: major Milestone: sage-9.2
Component: user interface Keywords:
Cc: gh-mwageringel, tscrim, nthiery Merged in:
Authors: Matthias Koeppe Reviewers: Markus Wageringel
Report Upstream: N/A Work issues:
Branch: 62de65d (Commits) Commit:
Dependencies: #30106 Stopgaps:

Description (last modified by mkoeppe)

This is something that's been discussed before but I don't think there's a ticket for it.

Python 3 allows unicode word-constituent 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 tab-completion for many unicode characters: https://ipython.readthedocs.io/en/stable/api/generated/IPython.core.completer.html#latex-and-unicode-completion (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 (k-th 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 8 months ago by mkoeppe

  • Milestone changed from sage-9.1 to sage-9.2

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.

comment:2 Changed 5 months ago by mkoeppe

  • Cc gh-mwageringel added
  • Dependencies set to #30106

comment:3 in reply to: ↑ description Changed 5 months ago by gh-mwageringel

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 4 months ago by mkoeppe

  • Authors set to Matthias Koeppe
  • Description modified (diff)

comment:5 Changed 4 months ago by mkoeppe

  • Branch set to u/mkoeppe/provide_unicode_aliases_for_some_globals_in_python_3

comment:6 Changed 4 months ago by mkoeppe

  • Commit set to 11aeb1542b40a8703f75f5ee38915cd91488d895
  • Description modified (diff)
  • Status changed from new to needs_review

New commits:

11aeb15Add globals σ, Γ, ψ, ζ, π

comment:7 Changed 4 months ago by mkoeppe

  • Cc tscrim added

comment:8 Changed 4 months ago by mkoeppe

  • Cc nthiery added

comment:9 Changed 4 months ago by gh-mwageringel

  • 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 4 months ago by mkoeppe

Interactively, the failing test fails even harder:

sage: import_statements(pi)
TypeError: <class 'object'> is a built-in class

comment:11 follow-up: Changed 4 months ago by gh-mwageringel

comment:12 Changed 4 months ago by git

  • Commit changed from 11aeb1542b40a8703f75f5ee38915cd91488d895 to 3d602ca0a27ebf124059423bc834415dcc86cc39

Branch pushed to git repo; I updated commit sha1. New commits:

3d602cafind_object_modules: Ignore errors from modules where getsource fails

comment:13 Changed 4 months ago by mkoeppe

Perhaps this fix needs to be pushed into sageinspect

comment:14 Changed 4 months ago by git

  • Commit changed from 3d602ca0a27ebf124059423bc834415dcc86cc39 to 62de65d207690234003087e9ef39ef4a46e53ba9

Branch pushed to git repo; I updated commit sha1. New commits:

1b21c16sage.misc.dev_tools.import_statements: Ignore __mp_main__ module as well
62de65dsage.misc.dev_tools.import_statements: If both ascii and unicode identifiers name an object, prefer ascii

comment:15 Changed 4 months ago by mkoeppe

  • Status changed from needs_work to needs_review

comment:16 in reply to: ↑ 11 ; follow-up: Changed 4 months ago by mkoeppe

Replying to gh-mwageringel:

This seems to be related to https://groups.google.com/forum/#!topic/sage-devel/7qelSgBOL-0.

I'll not work on this one

comment:17 in reply to: ↑ 16 Changed 4 months ago by gh-mwageringel

  • 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 4 months ago by mkoeppe

Thank you.

comment:19 Changed 3 months ago by vbraun

  • 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 3 months ago by embray

  • Commit 62de65d207690234003087e9ef39ef4a46e53ba9 deleted

Oh cool, I didn't know this was finally implemented ^^

comment:21 Changed 3 months ago by embray

I think this should probably be mentioned in the documentation though.

Note: See TracTickets for help on using tickets.