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?

  • 7
    $\begingroup$ That would be the argument of the function Derivative[n][f]. As a concrete example: Derivative[2][Sin][x] is the same as -Sin[x]. $\endgroup$ Jun 26, 2015 at 20:58

1 Answer 1


It's easier to follow if you try out Derivative[1][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[10]

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.

  • $\begingroup$ Another way of looking at the effect of Derivative[] is to use Operate[]: Operate[Derivative[2], Sin[x]] yields the second derivative -Sin[x]. $\endgroup$ Jun 27, 2015 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.