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)
> is.prim(primes(200,300))
> 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!

6 Responses to “bug in schoolmath”

  1. Bill Venables Says:

    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…)

  2. […] 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): […]

  3. 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

  4. […] a function of the (still bugged!) schoolmath package. We thus have the […]

  5. still not fixed :(

  6. […] 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 […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: