从Mathematica函数返回相等 [英] Return equality from Mathematica function
问题描述
我有一个返回等号的函数,我想打印该等号,例如
,x == y或2x + 5 == 10。
这些对于mathematica通常没有任何意义,它无法简化它。
I have a function that returns equalities, which I want to print, for example, x==y, or 2x+5==10. These usually have no meaning for mathematica, it cannot simplify it furhter.
但是,有时双方都是平等的,但我希望能够打印未评估形式的相等性:也就是说,我希望Mathematica打印x == x,而不是True。
However, sometimes the both sides are equal, but I want to be able to print the equality in unevaluated form: that is, I want Mathematica to print x==x, and not True.
一个非常简单的示例:
Print[printableEqual[x,y]]
应打印x == y,而
should print x==y, while
Print[printableEqual[x,x]]
应打印x == x
编辑:
原因是我在图表之间有关系。我想返回类似的东西
The reason is that I have a relation among graphs. I would like to return things like
G1 == t*G2 + s*G3
其中t,s是整数,而Gi是Mathematica中的Graphics对象。
只需返回即可,效果很好,(因为Mathematica无法简化此类事情),但G1 == G1除外。
where t,s are integers, and Gi are Graphics objects in Mathematica. Just returning this works great, (Since Mathematica cannot simplify such things) EXCEPT G1 == G1 which will be True.
麻烦是使用Defer,或HoldForm给出
The trouble is that using Defer, or HoldForm gives
Private`lhs$714 == Private`rhs$714
作为输出,即包中的私有变量不作为我的图形进行评估。
as output, that is, the private variables in my package is not evaluated as my Graphics.
推荐答案
您可以使用 Defer
为此:
You can use Defer
to do this:
In[5]:= printableEqual[x_, y_] := Defer[x == y];
In[6]:= printableEqual[1, 2]
Out[6]= 1 == 2
这篇关于从Mathematica函数返回相等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!