MathGroup Archive 1994

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Question about Cases command.

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Re: Question about Cases command.
  • From: rubin at msu.edu (Paul A. Rubin)
  • Date: Wed, 29 Jun 94 13:07:38 EDT

>I am trying to grab a list of the derivatives of functions that
>appears in a large list of differential equations.  I have been using
>the Cases command to do this and have a question about some curious
>behavior.
>
>	Consider the list of two derivatives:
>
>In[1]:= {Derivative[1,2][a][x,y], Derivative[1,1][b][x,y]}
>
>           3       2
>          d a     d b
>Out[1]= {------, ------}
>           1  2    1  1
>         dx dy   dx dy
>
>
>	I would like to select the derivatives of "a" .  First let's
>	check the Head of the terms:
>
>In[2]:= myterms = %;
>
>In[3]:= Map[Head, myterms]
>
>          (1,2)   (1,1)
>Out[3]= {a     , b     }
>
>	Now try to uses Cases:
>
>In[4]:= Cases[myterms,_Derivative[__][a]]
>
>Out[4]= {}
>
>	Why didn't it select the "a" term out?

Mma read the pattern as an object with head Derivative, followed by a
sequence of objects inside brackets.  In other words, only "Derivative" was
associated with the initial blank (_).  The first term in the list *almost*
matches this (but for the [x, y]).

>Try:
>
>In[5]:= Cases[myterms, _Derivative[__][_]]
>
>Out[5]= {}

Similar problem.

>
>In[6]:= Cases[myterms, _Derivative[__][__]]
>
>           3       2
>          d a     d b
>Out[6]= {------, ------}
>           1  2    1  1
>         dx dy   dx dy
>
>	Ok, now why must I use two underscores in this form?  ( In[6] )
>	The "a" and the "b" are single elements.
>

_Derivative matches Derivative[1, 2].  The first [__] matches either [a] or
[b]. The second [__] matches [x, y].  You could get by with a single _ in
the first set of brackets (matching a or b), but not in the second.

>	BTW. Here is something which works.
>
>In[7]:= derivdepfn[deriv_] := Head[deriv][[1]];
>
>In[9]:= Select[myterms, (derivdepfn[#1] === a) &]
>
>           3
>          d a
>Out[9]= {------}
>           1  2
>         dx dy
>
>
>
>Scott A. Herod
>Program in Applied Mathematics
>University of Colorado, Boulder
>(sherod at newton.colorado.edu)
>
Going back to your original attempt, these work:

In[]:=  Cases[myterms, _Derivative[a][__] ]

In[]:=  Cases[myterms, Derivative[__][a][__] ]

Paul

**************************************************************************
* Paul A. Rubin                                  Phone: (517) 336-3509   *
* Department of Management                       Fax:   (517) 336-1111   *
* Eli Broad Graduate School of Management        Net:   RUBIN at MSU.EDU    *
* Michigan State University                                              *
* East Lansing, MI  48824-1122  (USA)                                    *
**************************************************************************
Mathematicians are like Frenchmen:  whenever you say something to them,
they translate it into their own language, and at once it is something
entirely different.                                    J. W. v. GOETHE






  • Prev by Date: Re: unwarranted assumption?
  • Next by Date: Re: Fortran code
  • Previous by thread: Re: Question about Cases command.
  • Next by thread: v2.2.2 for Windows and remote kernels