MathGroup Archive 2013

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

Search the Archive

Re: Finding a function within an arbitrary expression

  • To: mathgroup at
  • Subject: [mg131655] Re: Finding a function within an arbitrary expression
  • From: "Mannucci, Anthony J (335G)" <anthony.j.mannucci at>
  • Date: Mon, 16 Sep 2013 05:16:07 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:


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 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
 4800 Oak Grove Drive,         
 Pasadena, CA 91109

From: Itai Seggev <itais at<mailto:itais at>>
Date: Sunday, September 15, 2013 9:53 PM
To: Tony Mannucci <Anthony.J.Mannucci at<mailto:Anthony.J.Mannucci at>>
Cc: "mathgroup at<mailto:mathgroup at>" <mathgroup at<mailto:mathgroup at>>
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:
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:


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.

  • Prev by Date: Re: very odd failure of Solve
  • Next by Date: ReplacePart -> eliminate
  • Previous by thread: Re: Finding a function within an arbitrary expression
  • Next by thread: FindRoot