Re: Finding a function within an arbitrary expression
- To: mathgroup at smc.vnet.net
- Subject: [mg131655] Re: Finding a function within an arbitrary expression
- From: "Mannucci, Anthony J (335G)" <anthony.j.mannucci at jpl.nasa.gov>
- Date: Mon, 16 Sep 2013 05:16:07 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
Itai, I believe your message has a gap. Were you about to say something about the levelspec in MemberQ? If the levelspec is Infinity, I believe {{2}} will work, but 2 will still not. With levelspec {0,Infinity}, 2 will work alone. Thanks for the definition of ContainsQ. -Tony -- Tony Mannucci Supervisor, Ionospheric and Atmospheric Remote Sensing Group Mail-Stop 138-308, Tel > (818) 354-1699 Jet Propulsion Laboratory, Fax > (818) 393-5115 California Institute of Technology, Email > Tony.Mannucci at jpl.nasa.gov 4800 Oak Grove Drive, http://scienceandtechnology.jpl.nasa.gov/people/a_mannucci/ Pasadena, CA 91109 From: Itai Seggev <itais at wolfram.com<mailto:itais at wolfram.com>> Date: Sunday, September 15, 2013 9:53 PM To: Tony Mannucci <Anthony.J.Mannucci at jpl.nasa.gov<mailto:Anthony.J.Mannucci at jpl.nasa.gov>> Cc: "mathgroup at smc.vnet.net<mailto:mathgroup at smc.vnet.net>" <mathgroup at smc.vnet.net<mailto:mathgroup at smc.vnet.net>> Subject: [mg131655] Re: Finding a function within an arbitrary expression On Sat, Sep 14, 2013 at 06:04:39AM -0400, Mannucci, Anthony J (335G) wrote: Bob, Thanks for these elegant solutions. In my view, these subtle distinctions are not helpful to users of the language. Perhaps there are "too many" ways to do things in Mathematica, although of course that can help with optimization. It appears the language kind of evolved through a somewhat haphazard process, or at least evolved by "extreme" experts. It would have been helpful to design these functions to solve specific problems and encourage standardized uses of the functions. Instead, users must parse through a multitude of possibilities to get at the one that works. Perhaps "too many choices". Of course, Mathematica remains an extremely powerful language. The subtle differences between FreeQ and MemberQ sometimes bite even expert users. Still, they are driven by most common usage. MemberQ tests membership, somewhat like the immediate evaluation version of Element. Consider the following examples: MemberQ[2,2] MemberQ[{2},2] MemberQ[{{2}},2] The first is commonly understood to be False. 2 is not a member of 2, as 2 is atomic. The second is clearly True. The third is False, because--thinking in set-theoretic terms--it is a list contain {2}, not a list containing 2. This, of course, OTOH, FreeQ would return False for all three, because there's a 2 right there in the first argument. That's why the default level spec for FreeQ is {0, Infinity}, while for MemberQ it is {1}. BTW, a common idiom is to define ContainsQ[expr_, form_] := ! FreeQ[expr, form] which I believe is what you want and semantically easy to understand.