简体   繁体   English

从字面上呈现一个表达式,没有简化

[英]Render a sympy expression literally, with no simplification

I wonder how I can make sympy behave such that the expression is rendered literally and no defactoring occurs (4 under the sqrt) 我想知道我怎么能让sympy表现得像字面意思一样表达并且没有发生任何残骸(sqrt下4)

from sympy import init_session
init_session(quiet=true)
from sympy.interactive import printing
printing.init_printing(use_latex=True)
a=sqrt(4*A**2*Z**2)
a

gives

2 * sqrt(a**2*Z**2)

I'd rather would have it written as initially written (in the course of an educational text). 我宁愿把它写成最初写的(在教育文本的过程中)。 So how does one prevent sympy from doing any simplifications or resolving? 那么如何防止同情者进行任何简化或解决?

Use an "evaluate(False)" block to stop the simplifaction/evaluation rules: 使用“evaluate(False)”块来停止简化/评估规则:

(I am using Python 3.4, sympy 0.7) (我使用的是Python 3.4,sympy 0.7)

with evaluate(False):
    print(sqrt(4*x))

sqrt(4*x)
>>>

As of now, there is no way to do this with sympy. 截至目前,没有办法用同情心做到这一点。 It parses the input sqrt(4*A**2*Z**2) and stores the expression tree, along the way sorting the terms as it sees fit, combining all rational factors into one, etc. There is no information left about the original input. 它解析输入sqrt(4*A**2*Z**2)并存储表达式树,按照它认为合适的方式对术语进行排序,将所有合理因素合并为一个等等。没有任何关于它的信息。原始输入。

Reference: Issue #3846: Allow manipulation of raw expression trees , which was open in 2008. The issue does not appear likely to be resolved any time soon. 参考: 问题#3846:允许操作原始表达式树 ,该在2008年开放。该问题似乎不会很快得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM