1

在 Mathematica 中,“或”看起来是用双竖线定义的。请参阅https://reference.wolfram.com/language/ref/Or.htmlhttps://mathematica.stackexchange.com/a/119763

在 Mathics 2.1.0 中,这似乎不起作用:

In[16]:= If[1<0 || 2<3 || 3<4, 0, 1]
Syntax::sntxf: "If[1<0 " cannot be followed by " 2<3  3<4, 0, 1]" (line 1 of "<stdin>").

而“或”这个词似乎有效:

In[16]:= If[1<0 or 2<3 or 3<4, 0, 1]
Out[16]= 1

那么我必须||在 Mathematica 和orMathics 中使用,还是我弄错了?

4

1 回答 1

0

Mathics 有一个文档,尽管出于某种原因它是 pdf,https: //mathics.org/docs/mathics-latest.pdf

目前第 11 页(3. 语言教程的一部分):

比较和布尔逻辑

[...]

真值可以使用 ! (逻辑非)并使用 && (逻辑与)和 || 组合 (逻辑或):

>> !True
   False
>> !False
   True
>> 3 < 4 && 6 > 5
   True

&& 比 || 具有更高的优先级,即它的绑定更强:

>> True && True || False && False
   True
>> True && (True || False) && False
   False

基于此,我确实期望||&&工作。

此外,第 44 页上还有一个示例If[x == 0.0 && y <= 0, 0.0, Sin[x ^ y] + 1 / Min[x, 0.5]] + 0.5]

您的错误消息可能是这里的关键,因为||变成了那些带框的问号,这可能与字符编码有关。如果它是您正在运行的文件,则可能值得检查它是否为 ASCII。

于 2021-05-31T09:49:57.777 回答