What is the correct way to match a function in an expression in the way that
Cases[Sin[x] Cos[x], _Sin | _Cos, {0, Infinity}]
matches Sin
and Cos
?
How can I match those functions without list all function names? The following code not only matches functions, but also List,
Plus` and so on.
Cases[Sin[x] Cos[x], _?(MatchQ[Head@#, _Symbol] &), Infinity]
Should I express this question as matching a function not in a list such as {List, Plus, Times, ...}
?
List
is a function, a pattern that matches all functions must matchList
. If you want to exclude certain functions, such asList
from matching, look atExcept
. $\endgroup$Cases[Sin[x] Cos[x], _@_, {0, Infinity}]
for single-argument functions? $\endgroup$Exclude
. $\endgroup$