Ask Your Question

Error when using non ASCII characters as symbolic function name

asked 2020-02-27 14:16:21 -0500

Juanjo gravatar image

Since the adoption of Python 3, non ASCII characters can be used as identifiers in SageMath. So this is valid:

sage: π = pi
sage: def α(x):
....:     return cos(π*x)
sage: β = lambda x: x^3
sage: print(α(3)+β(3))

Such characters can be also used as symbolic variable names:

sage: δ = var("δ")
sage: expand((1+δ)^2)
δ^2 + 2*δ + 1

... or even as symbolic functions:

sage: μ = (x^2).function(x)
sage: μ
x |--> x^2
sage: μ(3)

However, if one tries to define the above symbolic function as usual, one gets an error:

sage: μ(x) = x^2
  File "<ipython-input-20-93337e923470>", line 1
    μ(x) = x**Integer(2)
SyntaxError: can't assign to function call

I think that this is a bug, isn't it?

edit retag flag offensive close merge delete



Yes, this is a bug in the preparser:

from sage.repl.preparse import preparse_calculus

To find the function name it uses a regex with the range [a-zA-Z_], which doesn't include μ.

rburing gravatar imagerburing ( 2020-02-27 17:32:40 -0500 )edit

Using unicode in SR names is a recipe for disaster: these names get shipped to all kinds of interfaces. I would not expect those to react kindly to unicode identifiers.

nbruin gravatar imagenbruin ( 2020-03-03 15:55:01 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2020-03-03 15:19:18 -0500

rburing gravatar image

updated 2020-03-03 15:52:10 -0500

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-02-27 14:16:21 -0500

Seen: 73 times

Last updated: Mar 03