4
$\begingroup$

I can extract the parameters of a single variable derivative with the rule

D[f[x], x] /. Derivative[order_][fcn_][variable_] ->
  {order, fcn, variable}

produces

{1, f, x}

How do I generalize this to the multivariate case? For example,

D[f[x, y], x, y] /. Derivative[order_][fcn_][variable_] ->
  {order, fcn, variable}

produces

Mathematica graphics

The match didn't work -- but I can't seem to reproduce the actual Mathematica display.

I'm sure there's some magic syntax that will accomplish the match. I tried a few variations to no avail. Can anyone help?

Thanks much.

$\endgroup$
7
$\begingroup$

You have to look at the FullForm or InputForm to see, how you can match your expression.

InputForm[D[f[x, y], x, y]]

(*
  Derivative[1, 1][f][x, y]
*)

The order in your second example is a sequence of numbers. The same is true for the variables you try to match. Therefore you have to use BlankSequence in your pattern

D[f[x, y], x, y] /. 
 Derivative[order__][fcn_][variable__] -> {{order}, fcn, {variable}}

(*
  {{1, 1}, f, {x, y}}
*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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