Subject: [PATCH] Errors with bern() and zerobern:false
From: Kris Katterjohn
Date: Sun, 27 Jan 2013 19:59:58 -0600
Hi everyone,
The combination of bern() and zerobern:false lead to incorrect results and
Lisp errors.
By default, bern(n) for odd n>16 gives this error:
(%i1) bern(17),zerobern:false;
Maxima encountered a Lisp error:
Error in MACSYMA-TOP-LEVEL [or a callee]: 0 is not of type LIST.
bern(n) also doesn't seem work correctly for n<=16 or even n>16 by default
either, although it's not a Lisp error:
(%i2) map(bern,makelist(k,k,0,16));
(%o2) [1,-1/2,1/6,0,-1/30,0,1/42,0,-1/30,0,5/66,0,-691/2730,0,7/6,0,-3617/510]
(%i3) map(bern,makelist(k,k,0,16)),zerobern:false;
(%o3) [1,-1/2,1/6,-1/30,5/66,-691/2730,7/6,-3617/510,43867/798,-174611/330,
854513/138,-236364091/2730,8553103/6,-23749461029/870,
8615841276005/14322,-7709321041217/510,2577687858367/6]
Notice how -1/30 and 1/42, which are present in %o2, are completely skipped in
%o3. The example in describe(bern) even shows this.
I have attached a *very* short patch to fix these problems. (Bernoulli
numbers with n=0,1,2 are handled separately, so everything below is for n>=3)
It looks like the Lisp error is caused because ($bern n) calls (bern n), which
calculates the new (odd!) entry, then *red returns 0 (instead of a list) and
then cadr is attempted on it. To fix this I simply have $bern call bern for
the 2*(n-1)'th Bernoulli number, which is the nth "entry" with the odds >=3
removed.
The other problem is fixed by indexing the *bn* and *bd* arrays using n-2
instead of n in this case.
I've also attached two patches for documentation. One updates the example for
bern, fixing what I mentioned above. The other adds a mention of zerobern to
the documentation for euler (which is also affected by it), as well as
updating the example to show the change in behavior with zerobern, like in the
example for bern (I thought this was related enough to include the patch here).
Let me know what you think.
Cheers,
Kris Katterjohn
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bern.patch
Type: text/x-patch
Size: 530 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20130127/6b9dfc7c/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bern-doc.patch
Type: text/x-patch
Size: 1011 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20130127/6b9dfc7c/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: euler-doc.patch
Type: text/x-patch
Size: 839 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20130127/6b9dfc7c/attachment-0002.bin>