Re: Programming an Infinite Sum
- To: mathgroup at smc.vnet.net
- Subject: [mg43338] Re: [mg43278] Programming an Infinite Sum
- From: Dr Bob <drbob at bigfoot.com>
- Date: Mon, 25 Aug 2003 04:10:49 -0400 (EDT)
- References: <200308231209.IAA25182@smc.vnet.net> <oprudndxu4amtwdy@smtp.cox-internet.com> <3F48E1F4.2050309@nccn.net>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
I've forgotten what your problem was, so let me find that... ah! Here it
is.
The term and sum functions are recursive, and there's a default limit on
how far back you can recurse. A simple solution, if you want sum[8000], is
to first compute the terms before that (at least, far enough to prevent the
error). To facilitate experiments, first isolate the definitions:
define := (
ClearAll[term, sum];
term[3] = 2/5;
term[n_Integer] /; n > 3 := term[n] = term[n - 1](Prime[n - 1] - 2)
/Prime[n];
term[n_] := term@Round@n;
sum[3] = term[3];
sum[n_Integer] /; n > 3 := sum[n] = sum[n - 1] + N@term[n];
sum[n_] := sum@Round@n)
This will give the recursion error:
define
sum[4096]
but this will not:
define
Last[sum /@ Range[3, 4096]]
or
define
sum /@ Range[3, 4096, 128]; sum[4096]
The intermediate sums have to be calculated anyway, so there's not a lot of
time wasted in doing it this way. The following is one way to make it an
invisible process for 'term', if the first term asked for has n < 10,291.
(I'm not sure why that's the limit in this case.)
defineTerm := (
ClearAll[term];
term[3] = 2/5;
term[n_Integer] /; n > 255 :=
(term[n - 128]; term[n] = term[n - 1](Prime[n - 1] - 2)/Prime[n]);
term[n_Integer] /; 256 > n > 3 :=
term[n] = term[n - 1](Prime[n - 1] - 2)/Prime[n];
term[n_] := term@Round@n)
defineTerm
term[10290] // N
Do similarly for 'sum', of course.
Bobby
On Sun, 24 Aug 2003 09:04:04 -0700, Allan Haley <ashaley at nccn.net> wrote:
> Thanks, Dr. Bob, for your programming expertise, and first attempts to
> test convergence/divergence using the plotting features. I had just
> about given up trying to manipulate i's, j's and k's to reproduce the
> recursive product when I wrote the group. Your completely different
> approach makes me appreciate how much I still have to learn about how to
> use Mathematica.
>
> I notice (on my machine) that I now get an error when I try to get the
> formula to spit out the nth sum, such as sum[8000]. It says that the
> reiteration limit of 4096 has been exceeded, and gives me an output in
> terms of "HoldSum" etc. Can you tell me what is happening? Is there a
> workaround?
>
> (Only if you have time and inclination, of course.) Thanks very much for
> what you did.
>
> Allan Haley
>
>
>
--
majort at cox-internet.com
Bobby R. Treat
- References:
- Programming an Infinite Sum
- From: "A.S. Haley" <ashaley@nccn.net>
- Programming an Infinite Sum