Re: patterns

• To: mathgroup at smc.vnet.net
• Subject: [mg101882] Re: [mg101864] patterns
• From: Leonid Shifrin <lshifr at gmail.com>
• Date: Mon, 20 Jul 2009 19:20:48 -0400 (EDT)
• References: <200907201000.GAA28316@smc.vnet.net>

```Hi Francisco,

In[1] =
answ = {11.2, {dUp[1] -> 0., dUp[2] -> 0., dUp[3] -> 0.,
dUp[4] -> 2.1, dUp[5] -> 0., dUm[1] -> 0., dUm[2] -> 2.6,
dUm[3] -> 0.5, dUm[4] -> 0., dUm[5] -> 0., dLp[1] -> 0.,
dLp[2] -> 0., dLp[3] -> 0., dLp[4] -> 1.4, dLp[5] -> 0.,
dLm[1] -> 0., dLm[2] -> 3.1, dLm[3] -> 1.5, dLm[4] -> 0.,
dLm[5] -> 0., a[1] -> 6.75, a[2] -> 1.25, c[1] -> 1.65,
c[2] -> 0.15}};

Some possibilities:

In[2] = Cases[answ[[2]],Verbatim[Rule][(_a|_c),_]]

Out[2]= {a[1]->6.75,a[2]->1.25,c[1]->1.65,c[2]->0.15}

In[3] = Cases[answ[[2]], HoldPattern[(_a | _c) -> _]]

Out[3] = {a[1]->6.75,a[2]->1.25,c[1]->1.65,c[2]->0.15}

Both Verbatim and HoldPattern here were used for the same purpose:
to make the Rule head not be interpreted as a part of Cases
semantics, but rather as a head for a pattern to match.

Regards,
Leonid

On Mon, Jul 20, 2009 at 3:00 AM, Francisco Gutierrez <fgutiers2002 at yahoo.com
> wrote:

> Dear Group:
> Ther output of a code I made (which includes a minimization) is of the
> following guise:
>
>
> {11.2,{dUp[1]->0.,dUp[2]->0.,dUp[3]->0.,dUp[4]->2.1,dUp[5]->0.,dUm[1]->0. ,dUm[2]->2.6,dUm[3]->0.5,dUm[4]->0.,dUm[5]->0.,dLp[1]->0.,dLp[2]->0.,dLp[3]->0.,dLp[4]->1.4,dLp[5]->0.,dLm[1]->0.,dLm[2]->3.1,dLm[3]->1.5,dLm[4]->0.,dLm[5]->0.,a[1]->6.75,a[2]->1.25,c[1]->1.65,c[2]->0.15}}
>
> Of this output, I want to capture only the a's and the c's. There is an
> easy and sloppy manner, but general and I think not slow, to do this because
> they appear always at the end of the output. But I wonder if it were
> possible to use pattern matching to make the same thing, something of the
> sort of Cases[myoutput, a[__]]. Is it possible? How can it be done?
> Thanks
> Francisco
>
>

```

• References:
• patterns
• From: Francisco Gutierrez <fgutiers2002@yahoo.com>
• Prev by Date: Re: Odd behavior?
• Next by Date: Re: Invisible - misleading documentation
• Previous by thread: Re: patterns
• Next by thread: Re: patterns