MathGroup Archive 2008

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

Search the Archive

Re: Re: Selecting Element from List via Pattern

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89468] Re: [mg89414] Re: [mg89396] Selecting Element from List via Pattern
  • From: Syd Geraghty <sydgeraghty at mac.com>
  • Date: Tue, 10 Jun 2008 03:41:52 -0400 (EDT)
  • References: <200806090626.CAA28027@smc.vnet.net>

There are some interesting options for achieving equivalent results  
using Mathematica but with very different levels of comprehensibility.

Below Bobby pointed to the use of Default _. as in:-

Cases[t, Times[_., Power[Subscript[a, 1], 3]]]

The documentation for Default gives an easy way to understand it, namely

_. represents an argument that can be omitted.

More simply one could use

Cases[t, Times[1, Power[Subscript[a, 1], 3]]]

or even better

Cases[t, Power[Subscript[a, 1], 3]]

This simple case leads one to think about  some very interesting posts  
recently about Mathematica documentation.

My observation is that Mathematica has become so extensive (and  
complex) that only a deep hierarchy of documentation types which are  
extensively cross referenced and searchable within a Mathematica session with  
at least current Google search capability and sophistication is going  
to meet the needs of as broad a user base now enjoyed by WRI.

(Phew ...what a run-on sentence)

Cheers ... Syd


Syd Geraghty B.Sc, M.Sc.

sydgeraghty at mac.com

My System

Mathematica 6.0.2.1 for Mac OS X x86 (64 - bit) (March 13, 2008)
MacOS X V 10.5.2
MacBook Pro 2.33 Ghz Intel Core 2 Duo  2GB RAM






On Jun 9, 2008, at 2:26 AM, Bob Hanlon wrote:

> t = List @@ Expand[(Sum[Subscript[a, i], {i, 1, 5}])^3];
>
> Your expression works for the case given
>
> Cases[t, Times[_, Power[Subscript[a, 2], 2]]]
>
> {3*Subscript[a, 1]*Subscript[a, 2]^
>       2, 3*Subscript[a, 2]^2*
>     Subscript[a, 3],
>   3*Subscript[a, 2]^2*Subscript[a,
>       4], 3*Subscript[a, 2]^2*
>     Subscript[a, 5]}
>
> However, it will not find power terms without another factor such as
>
> Cases[t, Times[_, Power[Subscript[a, 1], 3]]]
>
> {}
>
> Add a default
>
> Cases[t, Times[_., Power[Subscript[a, 1], 3]]]
>
> {Subscript[a, 1]^3}
>
>
> Bob Hanlon
>
> ---- immanuel.bloch at googlemail.com wrote:
>> Hello,
>>
>> I am trying to extract from a Power Series all elements with a
>> certain exponent, e.g.
>> let us say I have generated a list via
>>
>> t = Apply[List, Expand[(Sum[Subscript[a, i], {i, 1, 5}])^3]]
>>
>> How can I then extract all terms with e.g. a_2^2 in it or any other
>> exponent?
>>
>> I have tried something like
>>
>> Cases[t, Times[_, Power[Subscript[a,2],2]]]
>>
>> but this somehow only works with the exponent n=1 and no others...
>>
>> Does anybody know a solution to this pattern matching problem?
>>
>> Thanks!
>> Immanuel
>>
>
>



  • Prev by Date: Re: Major problem with 6.0.2.1
  • Next by Date: Re: Show and 6.0
  • Previous by thread: Re: Selecting Element from List via Pattern Matching
  • Next by thread: Re: Selecting Element from List via Pattern Matching