Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15068 > unrolled thread

Re: Finding a function within an arbitrary expression

Started byBob Hanlon <hanlonr357@gmail.com>
First post2013-07-01 09:43 +0000
Last post2013-07-30 03:14 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Finding a function within an arbitrary expression Bob Hanlon <hanlonr357@gmail.com> - 2013-07-01 09:43 +0000
    Re: Finding a function within an arbitrary expression amannucci <Anthony.J.Mannucci@jpl.nasa.gov> - 2013-07-30 03:14 +0000

#15068 — Re: Finding a function within an arbitrary expression

FromBob Hanlon <hanlonr357@gmail.com>
Date2013-07-01 09:43 +0000
SubjectRe: Finding a function within an arbitrary expression
Message-ID<kqrj00$4ao$1@smc.vnet.net>
data = {3*u[1, 0], u[0, 0]/10., 1/u[1, 0], f[u[1, 0]]};


data2 = Select[data, MemberQ[#, u[1, 0]] &]


{3*u[1, 0], 1/u[1, 0], f[u[1, 0]]}


Some other methods:


data2 = Cases[data, _?(MemberQ[#, u[1, 0]] &)] = DeleteCases[data, _?(! MemberQ[#, u[1, 0]] &)] = Select[data, ! FreeQ[#, u[1, 0]] &] = Cases[data, _?(! FreeQ[#, u[1, 0]] &)] = DeleteCases[data, _?(FreeQ[#, u[1, 0]] &)] = data[[First /@ Position[data, u[1, 0]]]]


True



Bob Hanlon




On Sun, Jun 30, 2013 at 3:29 AM, amannucci
<Anthony.J.Mannucci@jpl.nasa.gov>wrote:

> I am trying to figure out what that pattern is for the following. The
> difficulty here is that I can think textually, but not in Mathematica
> patterns.
>
> I am looking for a function u[1,0] within a list of expressions. The
> function might not be defined yet. For example, a list of expressions might
> be:
>
> {3*u[1,0], u[0,0]/10., 1/u[1,0], ...}
>
> I want to find all the expressions that have the function u[1,0] in it.
> There is certainly a way to do this "textually". How would one do this with
> patterns? Is it possible? Thank you.
>
>
>

[toc] | [next] | [standalone]


#15260

Fromamannucci <Anthony.J.Mannucci@jpl.nasa.gov>
Date2013-07-30 03:14 +0000
Message-ID<kt7b2v$djs$1@smc.vnet.net>
In reply to#15068
On Monday, July 1, 2013 2:43:28 AM UTC-7, Bob Hanlon wrote:
> data = {3*u[1, 0], u[0, 0]/10., 1/u[1, 0], f[u[1, 0]]};
> 
> 
> data2 = Select[data, MemberQ[#, u[1, 0]] &]
> 
> 
> {3*u[1, 0], 1/u[1, 0], f[u[1, 0]]}
> 
> 
> Some other methods: [snip]
> 
> 
> Bob Hanlon
> 
> 

Your top example is a good way to do it. I am completely mystified, however. I originally tried to do this with Cases, but that did not work because of expression levels. I did not specify an expression level when using Cases. 

You do not specify the level in your MemberQ call, but it works. Yet, this does not work:
MemberQ[{3*u[1, 0]}, u[1, 0]] gives False
but 
MemberQ[{3*u[1, 0]}, u[1, 0],Infinity] gives True

So why don't you need a level spec in your example (definition of data2)? It's as if creating a lambda function automatically inserts the level spec. 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web