Pb with unicode character

asked 2020-04-22 23:03:10 +0100

Cyrille gravatar image

The following code works perfectly

var("w0, pi, D, I")
A = matrix(SR, 2, 2, [[w0, 1],[w0-pi,1]])
y = vector([w0-D, w0-D-pi+I])
sol=A.solve_right(y)
sola=sol[0].full_simplify().function(D, pi, I, w0)
solb=sol[1].full_simplify().function(D, pi, I, w0)
f(x, D, pi, I, w0)=sola*x + solb
show("f(x, D, pi, I, w0)=", f(x, D, pi, I, w0))

But if I use \pi <tab> in replacement of pi, there is a Macsyma error

edit retag flag offensive close merge delete

Comments

Hello, @Cyrille! Unfortunately, I don't have a complete solution for this problem, so I am writing just a comment.

The problem seems to be in the full_simplify() command. Reading the code of this command, I can see that, eventually, it has to convert the Sage code to Maxima code, and, unfortunately, Maxima doesn't handle Unicode characters, like Greek letters. You can try this in order to reproduce the error:

\pi<TAB>._maxima_()

If all you want is to have the output written in LaTeX code, you can use the command pi = var("pi", latex_name=r"\pi"). Notice the letter r before the double-quote signs in the latex_name argument? That is in order to tell Sage to avoid executing the backslash, which is a escape-character for Python. That is called a raw string (thus the r)

dsejas gravatar imagedsejas ( 2020-04-23 03:42:26 +0100 )edit

This is the modified code:

var("w0, D, I")
pi = var("pi", latex_name=r"\pi")
A = matrix(SR, 2, 2, [[w0, 1],[w0-pi,1]])
y = vector([w0-D, w0-D-pi+I])
sol=A.solve_right(y)
sola=sol[0].full_simplify().function(D, pi, I, w0)
solb=sol[1].full_simplify().function(D, pi, I, w0)
f(x, D, pi, I, w0)=sola*x + solb
show("f(x, D," + latex(pi) + ", I, w0)=", f(x, D, pi, I, w0))

This is the result:

$$\newcommand{\Bold}[1]{\mathbf{#1}}f(x, D, {\pi} , I, w0)= -\frac{{\left(I - {\pi}\right)} x}{{\pi}} - \frac{D {\pi} - I w_{0}}{{\pi}}$$

In any case, using the latex_name argument should produce better results than using Unicode characters, since these are written with LaTeX's \verb, which is intended for verbatim text, and disrupts the math-mode.

dsejas gravatar imagedsejas ( 2020-04-23 03:49:30 +0100 )edit