Pattern matching a multivariate derivative - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-22T05:11:14Z https://mathematica.stackexchange.com/feeds/question/7876 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/7876 4 Pattern matching a multivariate derivative Tom Gladd https://mathematica.stackexchange.com/users/1667 2012-07-04T14:34:29Z 2012-07-04T14:50:40Z <p>I can extract the parameters of a single variable derivative with the rule</p> <pre><code>D[f[x], x] /. Derivative[order_][fcn_][variable_] -&gt; {order, fcn, variable} </code></pre> <p>produces </p> <pre><code>{1, f, x} </code></pre> <p>How do I generalize this to the multivariate case? For example,</p> <pre><code>D[f[x, y], x, y] /. Derivative[order_][fcn_][variable_] -&gt; {order, fcn, variable} </code></pre> <p>produces</p> <p><img src="https://i.stack.imgur.com/0ZhEw.png" alt="Mathematica graphics"></p> <p>The match didn't work -- but I can't seem to reproduce the actual Mathematica display.</p> <p>I'm sure there's some magic syntax that will accomplish the match. I tried a few variations to no avail. Can anyone help?</p> <p>Thanks much.</p> https://mathematica.stackexchange.com/questions/7876/-/7877#7877 7 Answer by halirutan for Pattern matching a multivariate derivative halirutan https://mathematica.stackexchange.com/users/187 2012-07-04T14:45:23Z 2012-07-04T14:45:23Z <p>You have to look at the <code>FullForm</code> or <code>InputForm</code> to see, how you can match your expression. </p> <pre><code>InputForm[D[f[x, y], x, y]] (* Derivative[1, 1][f][x, y] *) </code></pre> <p>The order in your second example is a <em>sequence of numbers</em>. The same is true for the variables you try to match. Therefore you have to use <code>BlankSequence</code> in your pattern</p> <pre><code>D[f[x, y], x, y] /. Derivative[order__][fcn_][variable__] -&gt; {{order}, fcn, {variable}} (* {{1, 1}, f, {x, y}} *) </code></pre>