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

*To*: mathgroup at smc.vnet.net*Subject*: [mg60788] Re: [mg60768] Re: Checking for a given phrase in an expression*From*: Andrzej Kozlowski <andrzej at yhc.att.ne.jp>*Date*: Thu, 29 Sep 2005 05:40:56 -0400 (EDT)*References*: <dhau80$is9$1@smc.vnet.net> <200509280541.BAA08338@smc.vnet.net>*Reply-to*: Andrzej Kozlowski <andrzej at akikoz.net>*Sender*: owner-wri-mathgroup at wolfram.com

Not quite right. Actually in this case Mathematica "can find the pattern" because the pattern matcher is a little bit more "intelligent" than would appear from your description and can make use of the commutativity and associativity of addition and multiplication (the Flat and Orderless attributes). Andrzej Kozlowski On 28 Sep 2005, at 14:41, dh wrote: > HI, > in general this is not possible. Mathematically it is in general not > even possible to decide if two expressions are identical or not. > Mathematica can compare patterns. Now consider the FullForm : > FullForm[1 + x + x y + Log[Sin[z]]] > --> Plus[1, x, Times[x, y], Log[Sin[z]]] > FullForm[x + Log[Sin[z]]] > --> Plus[x, Log[Sin[z]]] > you see the smaller pattern does not occur in the larger one. If you > want detect the sub-pattern you would have to interprete the > pattern for > meaning, something Mathematica can not do. > Of course if you are searching for a simplier pattern like: Log[Sin > [z]], > that is contained in the FullForm of the larger expression, > Mathematica will be > able to find it (e.g. with Position). > > If you really are a "workoholic" a could create a pattern recognition > system that can recognize a limited set of patterns by defining a > suitable "Normalform" for your expressions that would allow to > mechanically decide if a searched pattern is contained or not. > > sincerely, Daniel > > > 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! >> >> > >

**References**:**Re: Checking for a given phrase in an expression***From:*dh <dh@metrohm.ch>