MathGroup Archive 2005

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60800] Re: [mg60761] Re: [mg60744] Checking for a given phrase in an expression
  • From: Andrzej Kozlowski <andrzej at yhc.att.ne.jp>
  • Date: Thu, 29 Sep 2005 05:41:09 -0400 (EDT)
  • References: <200509270745.DAA18926@smc.vnet.net> <200509280540.BAA08299@smc.vnet.net>
  • Reply-to: Andrzej Kozlowski <andrzej at akikoz.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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:

Subsets[f[a,b,c,....]]

is the same as

f@@@Subsets[{a,b,c,...}]

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


aa=a*b+c;bb=a;


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


False

while with the pattern matching based approach it is:


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


SubExpressionQ[aa,bb]

True

Of course it is all a matter of interpretation.

Andrzej Kozlowski


On 28 Sep 2005, at 14:40, <bsyehuda at gmail.com> <bsyehuda at gmail.com>  
wrote:

>
> 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 gmail.com <
> lost.and.lonely.physicist at gmail.com> 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