Mathematica-为什么TreeForm [Unevaluated [4 ^ 5]]评估4 ^ 5? [英] Mathematica -- why does TreeForm[Unevaluated[4^5]] evaluate the 4^5?

查看:59
本文介绍了Mathematica-为什么TreeForm [Unevaluated [4 ^ 5]]评估4 ^ 5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我给Mathematica输入

If I give Mathematica the input

TreeForm[Unevaluated[4^5]]

我希望看到三个方框-电源,4和5.

I expect to see three boxes -- power, 4, and 5.

相反,我看到一个带有1024的框.任何人都可以解释吗?

Instead I see a single box with 1024. Can anyone explain?

推荐答案

比较

TreeForm@Unevaluated[4^5]  

TreeForm@Hold[4^5]  

从帮助中:

未评估[expr] 表示expr作为函数的参数出现时的未经评估的形式.

Unevaluated[expr] represents the unevaluated form of expr when it appears as the argument to a function.

按住[expr] 以未评估的形式维护expr.

Hold[expr] maintains expr in an unevaluated form.

因此,当Unevaluated [4 ^ 5]进入TreeForm时,它就会得到评估...

so, as Unevaluated[4^5] gets to TreeForm ... it gets evaluated ...

它的工作原理如下:

f[x_+y_]:=x^y;
f[3+4]
(*
-> f[7]
*)
f[Unevaluated[3+4]]
(*
->81
*)

这篇关于Mathematica-为什么TreeForm [Unevaluated [4 ^ 5]]评估4 ^ 5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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