Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11926 > unrolled thread

Sum pattern

Started by"Dave Snead" <dsnead6@charter.net>
First post2012-10-03 07:10 +0000
Last post2012-10-04 03:39 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Sum pattern "Dave Snead" <dsnead6@charter.net> - 2012-10-03 07:10 +0000
    Re: Sum pattern Ray Koopman <koopman@sfu.ca> - 2012-10-04 03:39 +0000

#11926 — Sum pattern

From"Dave Snead" <dsnead6@charter.net>
Date2012-10-03 07:10 +0000
SubjectSum pattern
Message-ID<k4godt$38r$1@smc.vnet.net>
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[4]:= x = f[a1, s] + f[a2, s] + f[a3, s]

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

In[6]:= y = f[First /@ x, s]

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

which is what I want.

However when I turn this into a rule

In[7]:= z = x /. (p : Plus[__f]) -> f[First /@ p, s]

Out[7]= 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?

Thanks in advance,
Dave Snead 


[toc] | [next] | [standalone]


#11938

FromRay Koopman <koopman@sfu.ca>
Date2012-10-04 03:39 +0000
Message-ID<k4j0d3$7mc$1@smc.vnet.net>
In reply to#11926
On Oct 3, 12:12 am, "Dave Snead" <dsne...@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[4]:= x = f[a1, s] + f[a2, s] + f[a3, s]
>
> Out[4]= f[a1, s] + f[a2, s] + f[a3, s]
>
> In[6]:= y = f[First /@ x, s]
>
> Out[6]= f[a1 + a2 + a3, s]
>
> which is what I want.
>
> However when I turn this into a rule
>
> In[7]:= z = x /. (p : Plus[__f]) -> f[First /@ p, s]
>
> Out[7]= 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?
>
> Thanks in advance,
> Dave Snead

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

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

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

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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web