Given expression
expr = y'[x]^3 + y'[x]*Log[y[x]*y'[x]^2] + y'[x]^(1/2) + x/y'[x]^7
$$y'(x)^3+\sqrt{y'(x)}+\frac{x}{y'(x)^7}+y'(x) \log \left(y(x) y'(x)^2\right)$$
The goal is pick all $y'(x)^n$ terms out anywhere they show. So the final list should be
$$\left\{\frac{1}{y'(x)^7},\sqrt{y'(x)},y'(x)^2,y'(x),y'(x)^3\right\}$$
The following first pattern finds some subset of them, and the second pattern finds the rest. But when used together using Alternatives not all pattern are found.
pat1 = _.*D[y[x], x]^n_.;
pat2 = _.*_[_. * D[y[x], x]^n_.];
Cases[expr, pat1 :> D[y[x], x]^n]
$$\left\{\frac{1}{y'(x)^7},\sqrt{y'(x)},y'(x),y'(x)^3\right\}$$
Cases[expr, pat2 :> D[y[x], x]^n]
$$\left\{y'(x)^2\right\}$$
So one would expect that using both in Alternative then the result will be combined. But it does not
Cases[expr, (pat1 | pat2) :> D[y[x], x]^n]
$$\left\{\frac{1}{y'(x)^7},\sqrt{y'(x)},y'(x)^2,y'(x)^3\right\}$$
You see, the $y'(x)$ does not show up.
Why is that? Should not all the patterns matched when combining the two patterns using | be the union of each pattern applied separately?
V 12.3.1 on windows 10

![{Derivative[1][y][x]}](../../images/f6b6f4482d70f15d025c9b2bdc254334.webp)







DeleteDuplicates@Cases[expr, (pat1 | pat2) :> D[y[x], x]^n, 2]? – kglr Nov 21 '21 at 10:51|not to have any effect on this. But it seems then|if I understand you, tries one level only (1), compared when there is only one pattern, which will try different levels then? Ok, I think I understand the issue if this is what it is. – Nasser Nov 21 '21 at 11:00pat1with level spec 3:DeleteDuplicates@Cases[expr, pat1 :> D[y[x], x]^n, 3]– kglr Nov 21 '21 at 11:03DeleteDuplicates@Cases[expr, pat1 :> D[y[x], x]^n, Infinity]also. My main question was I thought using|will just combine both results. I guess I did not know it will make difference. If you like to make this an answer, will accept it. – Nasser Nov 21 '21 at 11:06pat = y'[x]^(n_ : 0) ; Cases[expr, pat, -1] // DeleteDuplicates– Daniel Huber Nov 21 '21 at 11:12|, it did not give the union of each result when done separately. I did not know it will work differently. But it does. – Nasser Nov 21 '21 at 11:15Cases[expr, (pat1 | pat2) :> D[y[x], x]^n]andCases[expr, (pat2 | pat1) :> D[y[x], x]^n]give different results. (UseTraceon both to see the source of the difference). (The difference might have to do with this) – kglr Nov 21 '21 at 11:25