# What is the role of _ in this expression?

I'm fairly familiar with basic Mathematica, but some of its more advanced syntax (especially certain special characters) eludes me.

In the Scope section in the documentation of Collect, there's this curious bit at the end:

D[f[Sqrt[x^2 + 1]], {x, 3}];
Collect[%, Derivative[_][f][_], Together]


I understand that _ indicates any valid expression — it's essentially Mathematica's wildcard character.

In the above example, what do each of the blanks correspond to, syntactically?

I'm guessing the first blank indicates "collect terms of any order derivative", so the first blank corresponds to derivative order. If so, what about the second blank?

Along the same lines, why is there the third argument ([_]) at all? Shouldn't Derivative only have two bracketed arguments, the first indicating the set of derivative orders and the second indicating the function?

• That would be the argument of the function Derivative[n][f]. As a concrete example: Derivative[Sin][x] is the same as -Sin[x]. – J. M. will be back soon Jun 26 '15 at 20:58

It's easier to follow if you try out Derivative[Cos[#] &]. Since it returns another function (-Sin[#1] &), it too can be applied. Derivative[n] is a function which takes a function and returns a function, hence the 3 brackets.

By the way, try FullForm on the expression that is being collected on to see how you could precisely determine the pattern yourself: D[f[Sqrt[x^2 + 1]], {x, 3}] // FullForm

Finally, note that square brackets are actually a pattern structure. Example:

f[a_][b_] := a + b;

partials = f /@ Range
Through[partials]


This is generally refered to as Currying/partial application. I think in Mathematica it's rarely necessary and often confusing (mainly as a matter of convention), but it makes sense in the case of Derivative.

• Another way of looking at the effect of Derivative[] is to use Operate[]: Operate[Derivative, Sin[x]] yields the second derivative -Sin[x]. – J. M. will be back soon Jun 27 '15 at 3:25