Convert sympy tree expression to infix math string

27 views
Skip to first unread message

Anton Makarov

unread,
Aug 7, 2022, 4:01:33 AM8/7/22
to sympy
Hi, there! I use str function to convert sympy tree expression to infix math string. It works fine, except the case when i convert the expression in power, for example:
a = Symbol('a')
res = str(a**2)
print(res)
# a**2
Is there any way to convert sympy tree expression to Standart infix math string form:
a^2 instead of a**2 ?
Thanks...

David Bailey

unread,
Aug 7, 2022, 12:00:17 PM8/7/22
to sy...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/d1eb5de6-6333-447d-9583-50fe7a0ac0ddn%40googlegroups.com.

Why not simply take the math string and use Python to  replace "**" by "^" everywhere? That way you don't have to worry about the fact that "^" is a Python operator. You could also use the reverse replacement to 'reactivate' the string if necessary.

David

Reply all
Reply to author
Forward
0 new messages