MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Conditonal sum

  • To: mathgroup at
  • Subject: [mg50271] Re: Conditonal sum
  • From: "Peter Pein" <petsie at>
  • Date: Tue, 24 Aug 2004 06:22:06 -0400 (EDT)
  • References: <cgcigl$ep6$>
  • Sender: owner-wri-mathgroup at

"Christopher Grinde" <christopher.grinde at> schrieb im Newsbeitrag
news:cgcigl$ep6$1 at
> I am new to mathematica and could really need a tip on how to implement a
> conditional sum.  Pseudocode would be something like this
> EndSum=a;
> if j in Sm:
> EndSum=EndSum+f[j]
> end
> I have tried doing this by using an If-clause inside the sum-function, but
> this seems little elegant and is nor very suitable for symbolic
> Any advice would be highly appreciated
> Christopher Grinde
Hi Christopher,

first apply f to each element of Sm:
 f/@ Sm
then change the head of the result from List to Plus, which results in:
Plus @@ (f /@ Sm), or - in most cases faster:


Peter Pein, Berlin
to write to me, start the subject with [

  • Prev by Date: Random rook's tour of a rectangle
  • Next by Date: Re: Conditonal sum
  • Previous by thread: Re: Conditonal sum
  • Next by thread: Re: Conditonal sum