6

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?

jvriesem
  • 417
  • 3
  • 12

1 Answers1

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]
Through[partials[100]]

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.

amr
  • 5,487
  • 1
  • 22
  • 32