Bug in pattern test, or I did something wrong?

*To*: mathgroup at smc.vnet.net*Subject*: [mg125862] Bug in pattern test, or I did something wrong?*From*: Yi Wang <tririverwangyi at gmail.com>*Date*: Thu, 5 Apr 2012 05:51:18 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com

Hi, all, When I define a function using pattern test conditions, I got some unexpected Replace (or ReplaceAll) behaviour: ClearAll[f, g, a, x]; f[a_ /; MemberQ[{0, 1, 2}, a]] := 0; f[x] /. f[expr_] :> f[-expr] (* expect f[-x], but I got f[x] *) f[x] /. f[expr_] + a_. :> f[-expr] + a (* Even worse, Here I got f[-expr] + f[x], completely weird! *) PS: Workaround: if I use another form of pattern test, there is no problem: g[a_?MemberQ[{0, 1, 2}, #] &] := 0; g[x] /. g[expr_] :> g[-expr] (* g[-x] as desired *) g[x] /. g[expr_] + a_. :> g[-expr] + a (* g[-x] as desired *)

**Follow-Ups**:**Re: Bug in pattern test, or I did something wrong?***From:*Yi Wang <tririverwangyi@gmail.com>

**Re: Bug in pattern test, or I did something wrong?***From:*Bob Hanlon <hanlonr357@gmail.com>

**Re: Bug in pattern test, or I did something wrong?***From:*Christoph Lhotka <christoph.lhotka@fundp.ac.be>