# Finding derivatives occurring in an expression

I would like to find the derivatives of a function U[x,y,t] occurring in an expression X. I use

DeleteDuplicates[Cases[X, Derivative[__][U][__], Infinity]].


An output would be something like this:

{Derivative[1, 0, 0][U][x, y, t],
Derivative[0, 1, 0][U][x, y, t],
Derivative[0, 2, 0][U][x, y, t],
Derivative[1, 1, 0][U][x, y, t],
Derivative[2, 0, 0][U][x, y, t],
Derivative[0, 1, 1][U][x, y, t],
Derivative[1, 0, 1][U][x, y, t],
Derivative[0, 0, 1][U][x, y, t],
Derivative[1, 1, 1][U][x, y, t],
Derivative[0, 2, 1][U][x, y, t]}


However, if I want to find a particular nth derivative of U, say 3rd derivative, in the expression to get the following:

 {Derivative[1, 1, 1][U][x, y, t],
Derivative[0, 2, 1][U][x, y, t]}


how would I achieve that?

• do you have a specific example of an input? – Nasser Jun 16 at 17:16
• I have added more details. – Bran Jun 16 at 17:26
• I meant an example of the PDE itself, you want to find those patterns in, so to be clear. i.e. the PDE which to apply the pattern on. I can then show how to do it on the PDE. This way there is no confusion. It is what you call the expression X – Nasser Jun 16 at 17:31
• X can be any PDE, even a system of PDEs, not necessarily linear. Using the above function will result something like the output provided. – Bran Jun 16 at 17:34

You need to specialise your pattern:

DeleteDuplicates[Cases[X, Derivative[i__][U][__]/;Plus[i]==3, -1]]


X can be any PDE, even a system of PDEs, not necessarily linear.

getPatterns[expr_, pat_] :=
Last@Reap[expr /. a : pat :> Sow[a], _, Sequence @@ #2 &];

pde = Derivative[1, 1, 1][U][x, y, t] +
Derivative[0, 2, 1][U][x, y, t]^3 +
Derivative[0, 1, 1][U][x, y, t] + Sin[x] + F'[x] +
Derivative[3, 0, 0][U][x, y, t] + Derivative[2, 1, 0][U][x, y, t];

getPatterns[pde,
Derivative[x0_, y0_, t0_][U][_, _, _] /; x0 + y0 + t0 == 3]


Function getPatterns is thanks to Carl Woll.