As silly as it may sound, I would like to use compound greek letters as a single symbol in SymPy. For example, if the following is entered in a Jupyter notebook:
import sympy as sp
ab = sp.Symbol("alpha beta")
sp.pprint(ab)
ab
behaves as desired when used in symbolic manipulations, but the output is:
alpha beta
I would like the output to be:
α⋅β
I could use the subs command after manipulations, like so:
ab.subs({ab : sp.Symbol("alpha") * sp.Symbol("beta")})
but this is tedious and undesirable.
Symbol names can be any string, but the automatic conversion of greek letter names to greek letters for printing doesn't work for all input. I guess it doesn't try to split the string in spaces.
If you are using the Jupyter notebook, you can just set the symbol name to be the LaTeX of what you want
ab = Symbol(r'\alpha\cdot\beta')
(don't forget to prefix the string with r
, so that Python doesn't eat the backslashes)
If you are using plain text output, you can set it to the Unicode string. This should work in the Jupyter notebook as well, although it will render slightly differently since it will be rendering the actual Unicode characters instead of the LaTeX.
ab = Symbol(u'α⋅β')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With