Pattern Matching: Keep those summands not depending on x
- To: mathgroup at smc.vnet.net
- Subject: [mg63764] Pattern Matching: Keep those summands not depending on x
- From: "ben" <benjamin.friedrich at gmail.com>
- Date: Fri, 13 Jan 2006 04:49:10 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Dear all,
I have a complicated sum and want to extract all summands not depending
on x.
I have a clumsy way to do that, but I wonder whether there is a better
solution.
So that is what I have done:
(* The sum *)
exp0 = 1+x;
(* Thread a dummy function foo1 over the summands using FixedPoint *)
exp1=foo1[exp0];
foo2[exp_]:=exp/.{foo1[a_+b_]\[Rule]foo1[a]+foo1[b]}
exp2=FixedPoint[foo2/.{foo1[a_+b_]\[Rule]foo1[a]+foo1[b]},
exp1]/.{foo1[exp_]\[Rule]foo3[exp]};
(* Replace dummy function foo1 by another one f003
that keeps the terms not depending on
x and drops the others *)
foo3[exp_]:=If[FreeQ[exp,s],exp,0]
(* The result *)
exp2
Any help is appreciated
Ben