"Mark Hubbart" <discord / mac.com> schrieb im Newsbeitrag
news:154A61B0-6E0E-11D8-A7C0-000502FDD5CC / mac.com...
>
> On Mar 4, 2004, at 5:04 AM, Robert Klemme wrote:
>
> >
> > "Charles Comstock" <cc1 / cec.wustl.edu> schrieb im Newsbeitrag
> > news:c278e5$c4g$1 / newsreader.wustl.edu...
> >
> >> Hey you know you could stuff prime? as a method in Integer as well.
> >> Just run a miller-rabin primality test.  I'll see if I can't cook up
> >> some code for that and send it your way, it might be another
> >> interesting
> >> extension to have.
> >
> > IMHO it's better to have a PrimeTester class that does the checking
> > because for efficiency reasons I'd want to store detected prime
numbers
> > somewhere.  Just my 0.02 EUR.
>
> Why not store it in the number itself?

Because prime number testing

(a) tends to be slow due to its complexity

(b) there are several algorithms AFAIK with no standard that is best under
all circumstances

(c) because of (a) typically you calculate the property only once for each
number and thus have to store the result somewhere.

(d) you have to take care of concurrency issues when implementing it in
Number or Integer because multiple threads may try to get the prime?
property of the same number at the same time and numbers are used all over
the place (i.e. high likelyhood of concurrent usage of the same number
instance)

All in all prime number testing is a complex thing (although, looking from
the boolean outcome, it looks simple) that doesn't easily fit into a
standard implementation of basic number handling IMHO.

>  >> 23.instance_eval{@prime = true}
> => true
>  >> 24.instance_eval{@prime = false}
> => false
>  >> 23.instance_eval{@prime}
> => true
>  >> 24.instance_eval{@prime}
> => false

That's possible, true.

> Or were you meaning persistant storage, so that it would be available
> to other interpreters?

Nope.

Kind regards

    robert