MathGroup Archive 2005

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

Search the Archive

Re: Re: Checking for a given phrase in an expression

It seems to be an undocumented feature that Subsets works with  
expressions with heads other than List but what it seems to be based  
on the following rule:


is the same as


The OP never explained precisely what he meant by  "a phrase bb  
exists in aa" so many different interpretations are possible but note  
that with your approach a is not a "phrase" in a*b+c


MemberQ[Subsets[aa, Length[bb]], bb]


while with the pattern matching based approach it is:

SubExpressionQ[a_, b_] := (a /. b -> Unique[]) =!= a



Of course it is all a matter of interpretation.

Andrzej Kozlowski

On 28 Sep 2005, at 14:40, <bsyehuda at> <bsyehuda at>  

> Out of the sleeve solution (I do not have time to have an  
> intelligent one
> right now) is to generate subsets of aa and then test if bb is a an  
> element
> in the list of subsets so
> MemberQ[Subsets[aa, Length[bb]], bb]
> returns True as expected
> yehuda
> On 9/27/05, lost.and.lonely.physicist at <
> lost.and.lonely.physicist at> wrote:
>> Hello everyone
>> Is it possible to ask Mathematica to check if a given phrase  
>> occurs in
>> an expression? Say I have
>> aa = 1 + x + x y + Log[Sin[z]]
>> and
>> bb = x + Log[Sin[z]]
>> Can Mathematica tell me such a phrase bb exists in aa? Can it tell me
>> its 'position' within the expression aa?
>> Thanks for the help!

  • Prev by Date: Re: Struggling with LaTeX output from Publicon
  • Next by Date: Re: Importing (and dealing with) multiple files
  • Previous by thread: Re: Checking for a given phrase in an expression
  • Next by thread: Re: Checking for a given phrase in an expression