bug in schoolmath
Neil Gunther has pointed out on his blog that the prime number decomposition R package schoolmath contains mistakes in the function primes, listing 1 as a prime number but also including decomposable numbers like 133 in its list of prime numbers:
> primes(100,140)
[1] 101 107 111 113 123 129 131 137
> primes(50,140)
[1] 51 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 133
[20] 137 139
> is.prim(primes(133)
[1] FALSE
> is.prim(primes(200,300))
[1] FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE
[13] TRUE TRUE TRUE TRUE TRUE TRUE
> sum(1-is.prim(primes(1,1000)))
[1] 10
> data(primlist)
> sum(1-is.prim(primlist[1:25000]))
[1] 3309
This is rather annoying and I hope it gets quickly fixed!
March 25, 2012 at 9:42 am
The whole package is an egregious example of bad programming in R and the package should be withdrawn as a dangerous example, particularly as it is (apparently) intended for use in schools! One look at the code is enough to show you that.
If you want a function to find prime numbers, there is the function primes() in the conf.design package. (This is admittedly an odd place to look for it, but I know it’s there because I wrote it…)
February 18, 2011 at 12:09 am
[…] A simple challenge in Le Monde this week: find the group of four primes such that any sum of three terms in the group is prime and the overall sum is minimised. Here is a quick exploration by simulation, using the schoolmath package (with its imperfections): […]
February 11, 2011 at 10:46 pm
Another bug is
> primes(start=13,end=21)
[1] 1 2 3 5 7 11 13 17 19
i.e. start and end are not accounted for if smaller than 19
October 18, 2010 at 12:11 am
[…] a function of the (still bugged!) schoolmath package. We thus have the […]
September 19, 2010 at 9:56 am
still not fixed :(
June 26, 2010 at 1:51 am
[…] thought about this recently when reading Christian Robert’s blog pointing out a post about errors in the package `schoolmath’. This was actually reported on a blog post by Neil Gunther. The problem involves finding prime […]