Sloane's On-line Encyclopedia of Integer Sequences has the following entry:
A110375 Numbers n such that Maple 9.5, Maple 10 and Maple 11 give the wrong answers for the number of partitions of n.
11269, 11566, 12376, 12430, 12700, 12754, 15013, 17589, 17797, 18181, 18421, 18453, 18549, 18597, 18885, 18949, 18997
I wonder whether that can be extended to Maple 12 as well (I don't have it to check.)
Alec
In Maple 12
gives the same answer as Maple 11.
Maple 11 and 12
... also for the others. It looks to me like the code for combinat[numbpart] has not changed recently. The OEIS entry mentions that Maple 6 got these right. I wonder
why the Maple 6 code was changed.
Error
I get
For several versions of Maple previous to Maple 9 that I have tried.
stack limit
In Unix/Linux/OSX the stack limit may need to be increased in the shell from which maple gets run, for this computation to complete.
I bumped my shell's stack limit up to 50000 (from 8192) on Solaris and saw combinat[numbpart](11269) come out correct in Maple 8 and incorrect in Maple 9. On 64bit Linux, with a stack limit of 10240, it completed (incorrectly) in Maple 11.02.
Of course, you may find that kernelopts(stacklimit) allows you to raise the working limit from within Maple. But that may depend on what the OS's shell's hard limit is.
On Windows, it may be trickier, I am not sure. You might try to utilize Maple's -T option, or its equivalent on Windows. I don't remember what hard limit might be compiled into the binaries. (For what it's worth, I do seem to recall that one can actually change the stacklimit built right into a Windows binary executable using MSVC++ tools.)
acer
Too many levels
It seems you can do it gradually, to avoid using too much stack at once.
(Maple 6)
231139177231303975514411787649455628959060199360109972557851\
519105155176180318215891795874905318274163248033071850
This is one less than the result returned by Maple 9 to 12.
Still not fixed in Maple 12.01
While some bugs posted on this site (such as this one, for example) were fixed in Maple 12.01, this one wasn't.
It seems rather strange, especially because Joe Riel's simple fix suggested in this thread, corrects that for the mentioned values.
Alec
Timings
Also, it is interesting to compare timings. Here is the timing in SAGE:
sage: a=[ 11269, 11566, 12376, 12430, 12700, 12754, 15013, 17589, 17797, 18181, 18421, 18453, 18549, 18597, 18885, 18949, 18997, 101269, 501269 ]
sage: time b=[number_of_partitions(n) for n in a]
CPU times: user 0.15 s, sys: 0.00 s, total: 0.15 s
Wall time: 0.15
Here are the correct last 2 digits for those who is interested,
sage: for n in b: print n%100,
....:
50 48 86 95 91 45 81 90 83 54 77 59 0 15 35 0 12 65 25
The last 2 terms which are terms of the sequence, but not necessarily the next terms, were added by Robert Gerbicz.
One more timing:
sage: time c=number_of_partitions(10^9)
CPU times: user 35.38 s, sys: 0.00 s, total: 35.38 s
Wall time: 35.38
I wonder how long it would take Maple to calculate that.
Alec
Benchmark
Not related to the correctness of the calculations, could somebody who has Sage, Mathematica, Maple, and Pari on the same computer, post the timings of calculations of the number of partitions function for, say, powers of 10, such as 10^4, 10^5, 10^6, 10^7, 10^8, and 10^9 in these systems?
I have everything else except Maple, so that wouldn't be especially interesting for Mapleprimes.
Alec
Rademacher
It appears as though the newer code uses an approximation to Rademacher's series for the partition function. To "fix" it, I modified the exit condition:
With that change, the results for the given values agree with the expected values.
Rademacher
Just guessing, but I'd suspect there might still be cases, maybe several orders of magnitude larger, where this would give the wrong answer. It would be nice to have a method that is provably correct.
Presumably
Agreed. I know nothing about the particular algorithm, just printed the code, noted that it appears to be a truncation of Rademacher's infinite sum, and made an adjustment to the termination condition. My first try, 0.05, worked for all but one of the list of known failures (I forget which, but it was closer to the beginning (smaller values) than the end). Fortunately, it is easy to change the value using subs...
Ramanujan congruences
I would also add testing for Ramanujan congruences - they can be used only for some n, but for those n they would add some confidence that the answer is correct, and it is easy to test them.
Alec
Testing and Review
Such procedures, obviously, should be exhaustively tested for all values of n up to the values for which it is possible. And values in this sequence seems to be in the available range (unless the timing is even worse than I expected.)
The absence of such testing makes other similar functions suspicious, too.
Also, it seems as if the exit condition should be not constant, but depending on n, and values of it could be guessed using series of random values of n in various intervals, with exhaustive testing after that.
Another thing seems clear - either the procedure was not reviewed before including it in the released product, or the reviewers did not qualify to do the review.
I wouldn't blame the person who wrote the code - such things usually happen, but the procedure including testing and review should exist to prevent them.
Alec
Update
11269, 11566, 12376, 12430, 12700, 12754, 15013, 17589, 17797, 18181, 18421, 18453, 18549, 18597, 18885, 18949, 18997, 20865, 21531, 21721, 21963, 22683, 23421, 23457, 23547, 23691, 23729, 23853, 24015, 24087, 24231, 24339, 24519, 24591, 24627, 24681, 24825, 24933, 25005, 25023, 25059, 25185, 25293, 27020
Alec
SAGE calculations
And here are the SAGE calculations for the updated list of values:
sage: a=[11269, 11566, 12376, 12430, 12700, 12754, 15013, 17589, 17797, 18181, 18421, 18453, 18549, 18597, 18885, 18949, 18997, 20865, 21531, 21721, 21963, 22683, 23421, 23457, 23547, 23691, 23729, 23853, 24015, 24087, 24231, 24339, 24519, 24591, 24627, 24681, 24825, 24933, 25005, 25023, 25059, 25185, 25293, 27020]
sage: b=map(number_of_partitions,a)
sage: print map(lambda n: n%100, b)
[50, 48, 86, 95, 91, 45, 81, 90, 83, 54, 77, 59, 0, 15, 35, 0, 12, 88, 94, 79, 14, 63, 68, 44, 28, 33, 5, 61, 74, 69, 6, 45, 15, 55, 18, 7, 6, 34, 0, 1, 40, 80, 1, 13]
Alec
mod
I tested the three Ramanujan congruence identities (5, 7, and 11) for all appropriate integers between 20,000 and 30,000 with the modification I mentioned (replace 0.1 with 0.03). All passed.
Compiler:-Compile
I didn't see the procedure's code. Could it be possible refined for using Compiler:-Compile? The C procedure should be much faster and allow testing for larger values of n.
Using pentagonal recurrences (for calculating the partition function modulo some number, say 2^32 - in this case the modulus need not to be included - the usual addition would do that automatically in case of overflowing) can be written rather simple in the way that Compiler:-Compile can be used. I'm not sure how far it can go, but probably further than current numbpart, so that could be used for testing, too.
Alec
system and SAGE
Another way of writing the numbpart (and many others) command would be using system command (or ssystem?) and SAGE - that would be both fast and correct. The only problem with that is that SAGE is GPLed, so it can't be distributed with Maple. The call to it still might be legal - IANAL.
Alec
checking with Pari
I made brute interface to Pari some time ago and posted it at this board, here is the result for the 'updated list' as pdf: Maple is off by 1 against Pari (which may be the underlying used in SAGE). My DLL is not very fast (it is on Windows and does not use GMP), but for the timing shown ~ 0.37 sec is for Pari, the rest is overhead + Maple's time (~ half a minute).
PS: calling SAGE is not illegal, GPL does mean something different (~making money by selling using otherones code without publishing)
www.mapleprimes.com/files/102_check_numbpart_Maple11_vs_Pari.pdf (22 Kb)
Edited to fix the link ...
Well done
Axel,
For some functions SAGE uses Pari, as well as a series of other systems, GAP, Singular, Maxima etc.
number_of_partitions, however, is a pure SAGE function. Currently, it seems to be the best in the field. It beats Pari, and it beats Mathematica improving the speed in several times, not talking about Maple, which seems to be not able to calculate such things as numbpart(10^9) at all, either correctly or wrong.
Alec
The code to compute the
The code to compute the number of partitions was written by Jonathan Bober who is a grad student at Michigan. It is fairly highly optimized C code that uses the GMP, MPFR, and quaddouble libraries.
--Mike
P.S. Using 5 lines in Sage, I was able to get the following additional terms for the sequence:
30270, 31679, 31720, 32890, 33081, 33554, 34027, 35090, 35231, 35833, 37317, 38058, 38868, 38950, 38958, 39183