SymPy 相当于 mathematica 中的 HoldForm [英] SymPy equivalent to HoldForm in mathematica

查看:27
本文介绍了SymPy 相当于 mathematica 中的 HoldForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Mathematica 中,可以防止系统在输入表达式时对其进行简化.语法如下:

HoldForm[x/x]

是否可以用 SymPy 做类似的事情?

解决方案

以下方法可以达到类似的效果.可能还有其他可用的我不知道.

import sympy as spx = sp.symbols('x')expr1 = x/xexpr2 = sp.S('x/x',evaluate=False)expr3 = sp.Mul(x, 1/x, 评估=假)打印(expr1)打印(expr2)打印(expr3)

<块引用>

1x/xx/x

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?

解决方案

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

这篇关于SymPy 相当于 mathematica 中的 HoldForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆