A programming puzzle.
- To: mathgroup at smc.vnet.net
- Subject: [mg60810] A programming puzzle.
- From: jackgoldberg at comcast.net
- Date: Thu, 29 Sep 2005 05:41:27 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hello everyone, I have a simple problem for which I would like an "elegant" solution. The problem is to convert the series a1*b1 + a2*b2 + a3*b3 + ... + an*bn into the equivalent series a1(b1 - b2) + (a1+a2)(b2 - b3) + ... +(a1 + a2 + ... + an-1)(bn-1 - bn) + (a1 + a2 + ... + an)bn This process, I believe, is called summation-by-parts. This problem is not hard to do; one simply separates the ai's from the bi's, constructs the "partial" sums for the ai series and the differences for the bi series. Then a dot product gets the answer. I am interested in a more elegant solution, if one exists. Taking care of all special cases will probably make any solution rather inelegant, so I am taking the liberty granted to all posers of only allowing series which have at least two terms AND the bi's are not constants and bi = bj is prohibited unless i = j. (This is, in fact, the situation I am concerned with.) I think some of you will have fun connocting ingenious solutions ... Let me know if you find any. Incidentally, timing is not crucial in my applications of "summation-by-parts" nor is storage of intermediate computations a problem. Thanks! Jack Goldberg
- Follow-Ups:
- Re: A programming puzzle.
- From: János <janos.lobb@yale.edu>
- Re: A programming puzzle.
- From: <bsyehuda@gmail.com>
- Re: A programming puzzle.