[squeak-dev] Integer>>isPrime why reverting Knuth's algorithm P (probabilistic primality test) with iteration over division with even numbers?

Randal L. Schwartz merlyn at stonehenge.com
Tue Dec 29 13:41:09 UTC 2009


>>>>> "Juan" == Juan Vuletich <juan at jvuletich.org> writes:

Juan> A routine should not assume much about how it is going to be
Juan> used. Instead, it should make clear its assumptions and limitations so
Juan> callers will know. #isProbablyPrime or such, and a method comment with
Juan> exactly the text you quote is the best.

Integer currently has both #isPrime (exact) and #isProbablyPrime (very likely
correct for everything we care about).  Just override #isPrime for
LargePositiveInteger as ^self isProbablyPrime.

That way, people who don't want to peer under the hood will get reasonable
results, and those who do will know exactly what is happening, or can delete
the definition in LargePositiveInteger if they don't mind slowing everyone
down. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion



More information about the Squeak-dev mailing list