I can see the source of your confusion: If you use Head[f[x]]
and Head[5]
you get f
and Integer
respectively. Then, you read the documentation
Apply[f,expr] or f@@expr replaces the head of expr by f.
and you expect Cos@@5
to replace the Integer
head by Cos
. The way I explain it to myself is by saying Mathematica has two (types of) heads ;-) One type is for expressions such as f[x]
and the other is for expressions such as 5
. I even have names for them: explicit and implicit heads. Then I conclude: Apply
replaces explicit heads only.
Now, in {1,2}
, the head is an explicit one. Thus, Plus@@{1,2}=Plus@@List[1,2]=Plus[1,2]=3
.
The @
symbol is easier to understand. f@x
is just f[x]
. So, Plus@{1,2}=Plus[List[1,2]]
and the result is List[1,2]
because you are not adding anything to List[1,2]
. If you want to add something to List[1,2]
, it must be included as another parameter to Plus
. Try Plus[List[1,2],a]
.
As mentioned in the comments, the documentation does not warn about these two types of heads. If you look closely, you will find a warning in Possible Issues in Apply and in the 3rd statement within details in AtomQ. I would have expected some clarification in Everything Is an Expression. A naive reading of it suggests that 5
and Integer[5]
are the same thing.
@@
is described at length in the documentation forApply
.@
is harder to find in the documentation: seePrefix
, $\endgroup$?FunctionName
. But when you do type in?@
you get nothing useful, likewise for@@
. So my next step is usually a web search, but "at symbol mathematica" doesn't really return any useful results in Google either. $\endgroup$?@@
inside a notebook, that is not what I get as the output. To find that, I have to specifically open up the documentation center from the Help menu and type it into the search box. $\endgroup$