I (think I) understand the difference between == (semantic) and === (syntactic). So when comparing != and =!= I was expecting a similar difference. So can anyone explain why the third line in this code gives a different result than the other three lines?
Sin[g[u]] /. f_[x__] /; f == Sin -> {f, x}
Sin[g[u]] /. f_[x__] /; f === Sin -> {f, x}
Sin[g[u]] /. f_[x__] /; f != Tan -> {f, x}
Sin[g[u]] /. f_[x__] /; f =!= Tan -> {f, x}
Answer
The Sin!=Tan
rule is unevaluated, since there is not enough data to decide whether Sin
and Tan
may yield the same information. If they're not given arguments they're simply symbols. And !=
doesn't check for exact symbol equivalence, from the documentation "Unequal returns True if elements are guaranteed unequal, and otherwise stays unevaluated."
Evaluate: Sin!=Tan
on its own and you get back unevaluated Sin!=Tan
. There's not enough information for Mathematica to decide if the Symbols may yield something that is equivalent, so it stays unevaluated and thus doesn't trigger the conditional on the rule.
You may be confused because you know Sin[x]
and Tan[x]
mean different things. (Though recognize Sin[0]==Tan[0]
).
Note: Sin=!=Tan
absolutely evaluates to True
as they are not the exact same symbol. UnsameQ
returns True
unless the expressions on the lhs and rhs are strictly identical. (documentation)
Comments
Post a Comment