The Trunk: Kernel-dtl.381.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Kernel-dtl.381.mcz

commits-2
David T. Lewis uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-dtl.381.mcz

==================== Summary ====================

Name: Kernel-dtl.381
Author: dtl
Time: 23 January 2010, 2:56:10.622 pm
UUID: 70c5d3fd-a468-4289-b9b5-101cdaea72b8
Ancestors: Kernel-nice.380

Use probabilistic algorithm (Knuth) for testing primality of large integers, and add method comments for explanation.

Rationale for use of probabilistic algorithm provided by Enrico Spinielli:
  http://lists.squeakfoundation.org/pipermail/squeak-dev/2009-December/142372.html

=============== Diff against Kernel-nice.380 ===============

Item was changed:
  ----- Method: Integer>>isPrime (in category 'testing') -----
  isPrime
+ "Answer true if the receiver is a prime number. See isProbablyPrime for a probabilistic
+ implementation that is much faster for large integers, and that is correct to an extremely
+ high statistical level of confidence (effectively deterministic)."
 
  self <= 1 ifTrue: [ ^false ].
  self even ifTrue: [ ^self = 2].
  3 to: self sqrtFloor by: 2 do: [ :each |
  self \\ each = 0 ifTrue: [ ^false ] ].
  ^true!

Item was added:
+ ----- Method: LargePositiveInteger>>isPrime (in category 'testing') -----
+ isPrime
+ "Answer true if the receiver is a prime number. Use a probabilistic implementation that
+ is much faster for large integers, and that is correct to an extremely high statistical
+ level of confidence (effectively deterministic)."
+
+ ^ self isProbablyPrime!