Re: Pattern Matching: Keep those summands not depending on x
- To: mathgroup at smc.vnet.net
- Subject: [mg63777] Re: Pattern Matching: Keep those summands not depending on x
- From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
- Date: Sat, 14 Jan 2006 02:32:18 -0500 (EST)
- References: <dq7us0$40n$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, a) don't try Rule[] with patterns if you are not very sure abut that what you are doing b) expr = 1 + a + x*c^2 + Exp[-b*x] + Sin[omega*t]; DeleteCases[expr, _?(! FreeQ[#, x] &)] may help you. Regards Jens "ben" <benjamin.friedrich at gmail.com> schrieb im Newsbeitrag news:dq7us0$40n$1 at smc.vnet.net... > 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 >