Ask Your Question
1

Error when using non ASCII characters as symbolic function name

asked 2020-02-27 21:16:21 +0100

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))
26

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)
9

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

Comments

2

Yes, this is a bug in the preparser:

from sage.repl.preparse import preparse_calculus
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-28 00:32:40 +0100 )edit
1

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 22:55:01 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2020-03-03 22:19:18 +0100

rburing gravatar image

updated 2020-03-03 22:52:10 +0100

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

Stats

Asked: 2020-02-27 21:16:21 +0100

Seen: 297 times

Last updated: Mar 03 '20