       • To: mathgroup at yoda.physics.unc.edu
• Subject: Re: Question about Cases command.
• From: withoff (David Withoff)
• Date: Tue, 28 Jun 1994 15:45:07 -0500

```> In:= myterms = {Derivative[1,2][a][x,y], Derivative[1,1][b][x,y]};
>
>
>           (1,2)   (1,1)
> Out= {a     , b     }
>
> 	Now try to uses Cases:
>
> In:= Cases[myterms,_Derivative[__][a]]
>
> Out= {}
>
> 	Why didn't it select the "a" term out?  Try:
>
> In:= Cases[myterms, _Derivative[__][_]]
>
> Out= {}
>
> In:= Cases[myterms, _Derivative[__][__]]
>
>            3       2
>           d a     d b
> Out= {------, ------}
>            1  2    1  1
>          dx dy   dx dy
>
> 	Ok, now why must I use two underscores in this form?  ( In )
> 	The "a" and the "b" are single elements.
>
>
> Scott A. Herod
> Program in Applied Mathematics

Compare

In:= FullForm[myterms[]]

Out//FullForm= Derivative[1, 2][a][x, y]

with

In:= FullForm[_Derivative[__][_]]

Out//FullForm= Blank[Derivative][BlankSequence[]][Blank[]]

The pattern will match anything with a single argument and
with a head that matches Blank[Derivative][BlankSequence[]],
which means that the head must be something with one or more

The expression

Derivative[1, 2][a][x, y]

has two elements, so it fails the first test.

The pattern Blank[h] does literal comparisons of the head.
It does not use the Head function, and does not allow for
the effects of special pattern expressions (things like __).
For example:

In:= MatchQ[f[], Blank[f]]

Out= True

In:= MatchQ[f[], Blank[f[_]]]

Out= False

In:= MatchQ[f[_][], Blank[f[_]]]

Out= True

Also, the special input notation _h for Blank[h] works only
if h is a symbol.  The FullForm must be used if h is not
a symbol.  That is, _f parses as Blank[f], and will match
expressions, with element 0 and a head that matches _f, not
expressions with a head of f.  The pattern that matches
expressions with head f must be entered as Blank[f].

Dave Withoff
Research and Development
Wolfram Research

```

• Prev by Date: Re: *Matrix witihn matrix*
• Next by Date: Can you abort from the "Evaluate Notebook" process ?