Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9438
| From | Yi Wang <tririverwangyi@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Bug in pattern test, or I did something wrong? |
| Date | 2012-04-05 09:56 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jljq7o$d09$1@smc.vnet.net> (permalink) |
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 *)
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Bug in pattern test, or I did something wrong? Yi Wang <tririverwangyi@gmail.com> - 2012-04-05 09:56 +0000
csiph-web