Ask Your Question
1

Automatic substitution of unicode characters

asked 2020-05-10 02:26:55 -0500

Cyrille gravatar image

With Python3 sagemath accept unicode characters. But not necessary it's periferic friends as Maxima. So for instance $\beta$ could not be use in solve could we imagine an automatic substitution process such that when $\beta$ is use sagemath send for instance be to Maxima and in return know that it must substitute $\beta$ for be in the other way.

This is perfectly doable on the spot. What I want to know is if one can construct such a mechanism ?

edit retag flag offensive close merge delete

Comments

Short code block to illustrate the problem please.

Something we can copy and paste in a fresh Sage session.

Would save time for anyone interested in exploring.

slelievre gravatar imageslelievre ( 2020-05-10 04:56:37 -0500 )edit

1 answer

Sort by » oldest newest most voted
3

answered 2020-05-10 06:23:22 -0500

mwageringel gravatar image

The short answer is: You can enable unicode art for the display of the output and name your variables by the full Greek name. Then you get nicely formatted output:

sage: %display unicode_art
sage: β = var('beta')
sage: β
β
sage: (β^3 + β) / 2
 3
β    β
── + ─
2    2
sage: latex(β)
\beta

The rendering is done using Sympy. This only changes the appearance of the output, though. Internally the symbol is still represented by beta.

sage: str(β)
beta
sage: maxima(β)
_SAGE_VAR_beta
sage: _.sage()
β

The long answer: What you are asking for is technically possible and the framework for this mechanism already exists in Sage, but the unicode support has not been implemented yet. Usually the conversion to an interface is implemented by an underscore method. For example:

sage: x._maxima_()
_SAGE_VAR_x

(or related methods such as _maxima_init_, _maxima_lib_, _maxima_lib_init_, but in this case they all refer to _maxima_) and the conversion back to Sage is implemented in:

sage: x._maxima_()._sage_()
x

In this case, these two methods do not directly implement the conversion, but via a series of indirections they call https://github.com/sagemath/sage/blob... for the conversion to Maxima (and other interfaces) and https://github.com/sagemath/sage/blob... for the conversion from Maxima back to Sage. These are the places where the conversion should be improved to handle unicode. A possible implementation might be based on e.g. 'β'.encode('unicode-escape') to encode a unicode string as ASCII.

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-05-10 02:26:55 -0500

Seen: 50 times

Last updated: May 10