MathGroup Archive 1994

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

Search the Archive

Re: alternating sums

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg327] Re: [mg307] alternating sums
  • From: seligjm at vax.sbu.ac.uk
  • Date: Tue, 13 Dec 1994 12:08:00 BST

In response to Jack Goldberg's question, here is a pretty way of constructing
an alternating sum from a list:

  lst={a1,a2,a3,...};

  i=1;
  f[x_,y_]:=(i++,x+(-1)^i*y);
  Fold[f,0,lst]

This has the pleasant property that you don't need to know the length of the
list.  However, you do need to reset "i" every time you want to use it.  This
could be overcome by putting it all in a Module[], but now we are getting ugly!

Seasons Greetings
Jon Selig





  • Prev by Date: Re: alternating sums
  • Next by Date: Alternating sums
  • Previous by thread: Re: alternating sums
  • Next by thread: Alternating sums