Re:
- To: mathgroup at smc.vnet.net
- Subject: [mg46417] Re:
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Tue, 17 Feb 2004 07:05:48 -0500 (EST)
- References: <200402170441.XAA28435@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 17 Feb 2004, at 05:41, Oleksandr Pavlyk wrote: > Just curious, is it to be considered a bug that > > In[1]:= FreeQ[-1 (a+b), a+b ] > > Out[1]= True > > and at the same time > > In[2]:=FreeQ[ -2 (a+b), a+b ] > > Out[2]= False > > > I would appereciate community's opinion on the issue. > > Thank you, > Sasha > > > To understand pattern matching you always look at FullForm: FullForm[-1 (a+b)] Plus[Times[-1,a],Times[-1,b]] As you can see yourself there is not Plus[a,b] here. But FullForm[-2 (a+b)] Times[-2,Plus[a,b]] This time the reason for the difference is that -1(a+b) is always automatically expanded to -a - b -1(a+b) -a-b while -2(a+b) -2 (a+b) is not expanded. Of course you can prevent evaluation in the former case if you want to: FreeQ[Unevaluated[-1(a+b)],a+b] False In any case, in my opinion there is no problem here. Pattern matching uses the FullForm of expressions, so in all cases you need to understand FullForm before trying to use it and often it will not be what you expect. Andrzej Kozlowski Chiba, Japan http://www.mimuw.edu.pl/~akoz/