       Re: Sum pattern

• To: mathgroup at smc.vnet.net
• Subject: [mg128280] Re: Sum pattern
• From: Ray Koopman <koopman at sfu.ca>
• Date: Wed, 3 Oct 2012 23:39:35 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net
• References: <20120930000917.61B1A6865@smc.vnet.net> <k4godt\$38r\$1@smc.vnet.net>

```On Oct 3, 12:12 am, "Dave Snead" <dsne... at charter.net> wrote:
> Hi,
>
> I'm trying to put together a rule whose left hand side is a sum of arbitrary
> length whose elements all have the same head f.
>
> For example:
>
> In:= x = f[a1, s] + f[a2, s] + f[a3, s]
>
> Out= f[a1, s] + f[a2, s] + f[a3, s]
>
> In:= y = f[First /@ x, s]
>
> Out= f[a1 + a2 + a3, s]
>
> which is what I want.
>
> However when I turn this into a rule
>
> In:= z = x /. (p : Plus[__f]) -> f[First /@ p, s]
>
> Out= f[f[a1, s], s] + f[f[a2, s], s] + f[f[a3, s], s]
>
> Why isn't z equal to y?
> How can I make this rule work?
>

In:= x = f[a1,s] + f[a2,s] + f[a3,s]

Out= f[a1,s] + f[a2,s] + f[a3,s]

In:= x //. f[a_,c_] + f[b_,c_] -> f[a+b,c]

Out= f[a1+a2+a3,s]

```

• Prev by Date: Integrating over 3D vector
• Next by Date: How to solve a vector integral within a solid angle ?
• Previous by thread: Re: Sum pattern
• Next by thread: Re: Sum pattern