SymPy equivalent to HoldForm in mathematica

非 Y 不嫁゛ 提交于 2019-12-10 18:54:43

问题


In Mathematica, it is possible to prevent the system from simplifying expressions when they are entered. The syntax is as follows:

HoldForm[x/x]

Is it possible to do something similar with SymPy?


回答1:


The following approaches achieve a similar effect. There might be others available I am not aware of.

import sympy as sp

x = sp.symbols('x')

expr1 = x/x 
expr2 = sp.S('x/x', evaluate=False)
expr3 = sp.Mul(x, 1/x, evaluate=False)

print(expr1)
print(expr2)
print(expr3)
1
x/x
x/x



回答2:


You can also use with evaluate(False), like

with evaluate(False):
     print(x/x)


来源:https://stackoverflow.com/questions/40264977/sympy-equivalent-to-holdform-in-mathematica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!