SlideShare a Scribd company logo
1 of 17
Download to read offline
Graphcs an Ulam Spiral, with start in the center,
iterating in a outward spiraling, counterclockwise fashion returns a list of
ulamGraph start_: 1, end_: 1600,
algorithm_: "standard", attempts_: 10, returnData_: False :
s start;
ulamPrimePoints ;
i 0; i allows us to properly iterate in a positive or negative direction on the x,
y axis of the Ulam spiral.
p 0, 0 ;
numberOfPrimes 0;
The graphing pattern of the Ulam Spiral oscillates between y and x,
1 and 1 directions. We capture this behavior with 2 seperate for loops
While s end,
Here we iterate through in a positive or negative x direction
Do
If isPrimeQ s, algorithm, attempts ,
numberOfPrimes ; ulamPrimePoints Append ulamPrimePoints, p ;
p p 1 ^i 1, 0 ;
s ;,
x, 0, i ;
Here we iterate through in a positive or negative y direction
Do
If isPrimeQ s, algorithm, attempts ,
numberOfPrimes ; ulamPrimePoints Append ulamPrimePoints, p ;
p p 1 ^i 0, 1 ;
s ;,
y, 0, i ;
i ;
;
Sometimes, we may not want to print, and only want the ulam plot information
If returnData, Return ulamPrimePoints ,
Print "The number of primes in the range ",
start, " to ", end, " is ", numberOfPrimes ;
Print "The average probability of finding a prime in this range is ",
1.0 numberOfPrimes end start ;
range Ceiling Ceiling end start 2 ;
coordinateRange range, range ;
ListPlot ulamPrimePoints,
PlotRange coordinateRange , coordinateRange , AspectRatio 1
This function acquires the correct primality algorithm to test some integer n
isPrimeQ number_, algorithm_, attempts_ :
If MatchQ algorithm , "standard" , Return PrimeQ number ;
If MatchQ algorithm , "fermat" , Return fermatPrimeQ number, attempts ;
If MatchQ algorithm , "naive" , Return naivePrimeQ number ;
This is the most basic deterministic primality testing algorithm,
testing each divisor below the number in question until that numbers square root
naivePrimeQ number_ :
q 2;
While q number ,
If Mod number, q 0, Return False , q
;
Return True ;
This is Fermat's probabilistic algorithm, utilizing Fermat's little theorem
fermatPrimeQ n_, attempts_ :
i 0;
While i attempts,
a Random Integer, 1, n 1 ;
If expMod a, n, n a, Return False , i
;
Return True ;
This is a recursive modulus function that takes in an explicit
base, exponent, utilizing the property of exponents a^2p a^p ^2
expMod base_, exp_, m_ :
If exp 0, 1,
If Mod exp, 2 0, Mod expMod base, exp 2, m 2
, m ,
Mod base expMod base, exp 1 , m , m
ulamGraph 1, 1600, "standard"
ulamGraph 1, 1600, "naive"
ulamGraph 1, 20 000
2 UlamFinal.nb
ulamGraph 20 000, 40 000
ulamGraph 100 000 000 000 000, 100 000 000 010 000
ulamGraph 100 000 000 010 000, 100 000 000 050 000
ulamGraph 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000,
10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 010 000
ulamGraph 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000,
10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 100 000
ulamGraph
100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000,
100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 010 000
ulamGraph
100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000,
100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 100 000
ulamGraph
10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000,
10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
UlamFinal.nb 3
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 010 000
Here is some benchmarking
Timing PrimeQ 32 416 187 567
Timing naivePrimeQ 32 416 187 567
Timing fermatPrimeQ 32 416 187 567, 10
Timing fermatPrimeQ 32 416 187 567, 1000
Timing fermatPrimeQ 32 416 187 567, 10 000
Timing Table PrimeQ n , n, 1 000 000, 1 010 000 ;
Timing Table naivePrimeQ n , n, 1 000 000, 1 010 000 ;
Timing Table fermatPrimeQ n, 10 , n, 1 000 000, 1 010 000 ;
Timing Table fermatPrimeQ n, 100 , n, 1 000 000, 1 010 000 ;
Timing Table PrimeQ n , n, 100 000 000, 100 010 000 ;
Timing Table fermatPrimeQ n, 10 , n, 100 000 000, 100 010 000 ;
Timing Table fermatPrimeQ n, 100 , n, 100 000 000, 100 010 000 ;
The number of primes in the range 1 to 1600 is 259
The average probability of finding a prime in this range is 0.161976
4 UlamFinal.nb
20 10 10 20
20
10
10
20
The number of primes in the range 1 to 1600 is 272
The average probability of finding a prime in this range is 0.170106
UlamFinal.nb 5
20 10 10 20
20
10
10
20
The number of primes in the range 1 to 20 000 is 2264
The average probability of finding a prime in this range is 0.113206
6 UlamFinal.nb
60 40 20 20 40 60
60
40
20
20
40
60
The number of primes in the range 20 000 to 40 000 is 1943
The average probability of finding a prime in this range is 0.09715
UlamFinal.nb 7
60 40 20 20 40 60
60
40
20
20
40
60
The number of primes in the range 100 000 000 000 000 to 100 000 000 010 000 is 305
The average probability of finding a prime in this range is 0.0305
8 UlamFinal.nb
40 20 20 40
40
20
20
40
The number of primes in the range 100 000 000 010 000 to 100 000 000 050 000 is 1179
The average probability of finding a prime in this range is 0.029475
UlamFinal.nb 9
100 50 50 100
100
50
50
100
The number of primes in the range 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
to 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 010 000 is 80
The average probability of finding a prime in this range is 0.008
10 UlamFinal.nb
40 20 20 40
40
20
20
40
The number of primes in the range 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
to 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 100 000 is 791
The average probability of finding a prime in this range is 0.00791
UlamFinal.nb 11
150 100 50 50 100 150
150
100
50
50
100
150
The number of primes in the range
100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 to
100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 010 000 is 34
The average probability of finding a prime in this range is 0.0034
12 UlamFinal.nb
40 20 20 40
40
20
20
40
The number of primes in the range
100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 to
100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 100 000 is 434
The average probability of finding a prime in this range is 0.00434
UlamFinal.nb 13
150 100 50 50 100 150
150
100
50
50
100
150
14 UlamFinal.nb
The number of primes in the range
10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 to
10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 010 000 is 4
The average probability of finding a prime in this range is 0.0004
UlamFinal.nb 15
40 20 20 40
40
20
20
40
9.922618282587337`*^-16 , True Built in prime test for 32416187567
1.1229999999999967` , True Naive prime test for 32416187567
6.543376951384516`*^-15 , True Fermat prime test with 10 attempts, for 32416187567
0.4520000000000069` , True Fermat prime test with 1,000 attempts, for 32416187567
4.289999999999993` , True Fermat prime test with 10,000 attempts, for 32416187567
0.016000000000005718` , Null
Built in prime test for all the numbers between 1000000 and 1010000
6.598999999999997` , Null
Naive prime test for all the numbers between 1000000 and 1010000
3.9310000000000063` , Null Fermat prime test with 10 attempts,
for all the numbers between 1000000 and 1010000
16 UlamFinal.nb
19.921000000000006` , Null Fermat prime test with 100 attempts,
for all the numbers between 1000000 and 1010000
0.015999999999988926` , Null
Built in prime test for all the numbers between 100000000 and 100010000
4.8520000000000065` , Null Fermat prime test with 10 attempts,
for all the numbers between 100000000 and 100010000
20.716999999999988` , Null Fermat prime test with 100 attempts,
for all the numbers between 100000000 and 100010000
UlamFinal.nb 17

More Related Content

Viewers also liked

_Banter_from_the_Bench_The_use_of_humour_in
_Banter_from_the_Bench_The_use_of_humour_in_Banter_from_the_Bench_The_use_of_humour_in
_Banter_from_the_Bench_The_use_of_humour_in
Jack Oakley
 
104.6.11創意思考激發
104.6.11創意思考激發104.6.11創意思考激發
104.6.11創意思考激發
a05100126
 
104.4.9雁行理論
104.4.9雁行理論104.4.9雁行理論
104.4.9雁行理論
a05100126
 

Viewers also liked (10)

Chamadas matadoras que vendem como loucas
Chamadas matadoras que vendem como loucasChamadas matadoras que vendem como loucas
Chamadas matadoras que vendem como loucas
 
Boletín XXII junio 2016
Boletín XXII junio 2016Boletín XXII junio 2016
Boletín XXII junio 2016
 
_Banter_from_the_Bench_The_use_of_humour_in
_Banter_from_the_Bench_The_use_of_humour_in_Banter_from_the_Bench_The_use_of_humour_in
_Banter_from_the_Bench_The_use_of_humour_in
 
What is the Certified Protection Professional (CPP) Designation?
What is the Certified Protection Professional (CPP) Designation?What is the Certified Protection Professional (CPP) Designation?
What is the Certified Protection Professional (CPP) Designation?
 
104.6.11創意思考激發
104.6.11創意思考激發104.6.11創意思考激發
104.6.11創意思考激發
 
104.4.9雁行理論
104.4.9雁行理論104.4.9雁行理論
104.4.9雁行理論
 
Carteles julio cortazar 1ºb
Carteles julio cortazar 1ºbCarteles julio cortazar 1ºb
Carteles julio cortazar 1ºb
 
如何成為科技業搶手的整合性人才
如何成為科技業搶手的整合性人才如何成為科技業搶手的整合性人才
如何成為科技業搶手的整合性人才
 
rebecca cv
rebecca cvrebecca cv
rebecca cv
 
Peer assessment instructions
Peer assessment instructionsPeer assessment instructions
Peer assessment instructions
 

UlamSpiralMathematica

  • 1. Graphcs an Ulam Spiral, with start in the center, iterating in a outward spiraling, counterclockwise fashion returns a list of ulamGraph start_: 1, end_: 1600, algorithm_: "standard", attempts_: 10, returnData_: False : s start; ulamPrimePoints ; i 0; i allows us to properly iterate in a positive or negative direction on the x, y axis of the Ulam spiral. p 0, 0 ; numberOfPrimes 0; The graphing pattern of the Ulam Spiral oscillates between y and x, 1 and 1 directions. We capture this behavior with 2 seperate for loops While s end, Here we iterate through in a positive or negative x direction Do If isPrimeQ s, algorithm, attempts , numberOfPrimes ; ulamPrimePoints Append ulamPrimePoints, p ; p p 1 ^i 1, 0 ; s ;, x, 0, i ; Here we iterate through in a positive or negative y direction Do If isPrimeQ s, algorithm, attempts , numberOfPrimes ; ulamPrimePoints Append ulamPrimePoints, p ; p p 1 ^i 0, 1 ; s ;, y, 0, i ; i ; ; Sometimes, we may not want to print, and only want the ulam plot information If returnData, Return ulamPrimePoints , Print "The number of primes in the range ", start, " to ", end, " is ", numberOfPrimes ; Print "The average probability of finding a prime in this range is ", 1.0 numberOfPrimes end start ; range Ceiling Ceiling end start 2 ; coordinateRange range, range ; ListPlot ulamPrimePoints, PlotRange coordinateRange , coordinateRange , AspectRatio 1
  • 2. This function acquires the correct primality algorithm to test some integer n isPrimeQ number_, algorithm_, attempts_ : If MatchQ algorithm , "standard" , Return PrimeQ number ; If MatchQ algorithm , "fermat" , Return fermatPrimeQ number, attempts ; If MatchQ algorithm , "naive" , Return naivePrimeQ number ; This is the most basic deterministic primality testing algorithm, testing each divisor below the number in question until that numbers square root naivePrimeQ number_ : q 2; While q number , If Mod number, q 0, Return False , q ; Return True ; This is Fermat's probabilistic algorithm, utilizing Fermat's little theorem fermatPrimeQ n_, attempts_ : i 0; While i attempts, a Random Integer, 1, n 1 ; If expMod a, n, n a, Return False , i ; Return True ; This is a recursive modulus function that takes in an explicit base, exponent, utilizing the property of exponents a^2p a^p ^2 expMod base_, exp_, m_ : If exp 0, 1, If Mod exp, 2 0, Mod expMod base, exp 2, m 2 , m , Mod base expMod base, exp 1 , m , m ulamGraph 1, 1600, "standard" ulamGraph 1, 1600, "naive" ulamGraph 1, 20 000 2 UlamFinal.nb
  • 3. ulamGraph 20 000, 40 000 ulamGraph 100 000 000 000 000, 100 000 000 010 000 ulamGraph 100 000 000 010 000, 100 000 000 050 000 ulamGraph 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000, 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 010 000 ulamGraph 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000, 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 100 000 ulamGraph 100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000, 100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 010 000 ulamGraph 100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000, 100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 100 000 ulamGraph 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000, 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 UlamFinal.nb 3
  • 4. 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 010 000 Here is some benchmarking Timing PrimeQ 32 416 187 567 Timing naivePrimeQ 32 416 187 567 Timing fermatPrimeQ 32 416 187 567, 10 Timing fermatPrimeQ 32 416 187 567, 1000 Timing fermatPrimeQ 32 416 187 567, 10 000 Timing Table PrimeQ n , n, 1 000 000, 1 010 000 ; Timing Table naivePrimeQ n , n, 1 000 000, 1 010 000 ; Timing Table fermatPrimeQ n, 10 , n, 1 000 000, 1 010 000 ; Timing Table fermatPrimeQ n, 100 , n, 1 000 000, 1 010 000 ; Timing Table PrimeQ n , n, 100 000 000, 100 010 000 ; Timing Table fermatPrimeQ n, 10 , n, 100 000 000, 100 010 000 ; Timing Table fermatPrimeQ n, 100 , n, 100 000 000, 100 010 000 ; The number of primes in the range 1 to 1600 is 259 The average probability of finding a prime in this range is 0.161976 4 UlamFinal.nb
  • 5. 20 10 10 20 20 10 10 20 The number of primes in the range 1 to 1600 is 272 The average probability of finding a prime in this range is 0.170106 UlamFinal.nb 5
  • 6. 20 10 10 20 20 10 10 20 The number of primes in the range 1 to 20 000 is 2264 The average probability of finding a prime in this range is 0.113206 6 UlamFinal.nb
  • 7. 60 40 20 20 40 60 60 40 20 20 40 60 The number of primes in the range 20 000 to 40 000 is 1943 The average probability of finding a prime in this range is 0.09715 UlamFinal.nb 7
  • 8. 60 40 20 20 40 60 60 40 20 20 40 60 The number of primes in the range 100 000 000 000 000 to 100 000 000 010 000 is 305 The average probability of finding a prime in this range is 0.0305 8 UlamFinal.nb
  • 9. 40 20 20 40 40 20 20 40 The number of primes in the range 100 000 000 010 000 to 100 000 000 050 000 is 1179 The average probability of finding a prime in this range is 0.029475 UlamFinal.nb 9
  • 10. 100 50 50 100 100 50 50 100 The number of primes in the range 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 to 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 010 000 is 80 The average probability of finding a prime in this range is 0.008 10 UlamFinal.nb
  • 11. 40 20 20 40 40 20 20 40 The number of primes in the range 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 to 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 100 000 is 791 The average probability of finding a prime in this range is 0.00791 UlamFinal.nb 11
  • 12. 150 100 50 50 100 150 150 100 50 50 100 150 The number of primes in the range 100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 to 100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 010 000 is 34 The average probability of finding a prime in this range is 0.0034 12 UlamFinal.nb
  • 13. 40 20 20 40 40 20 20 40 The number of primes in the range 100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 to 100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 100 000 is 434 The average probability of finding a prime in this range is 0.00434 UlamFinal.nb 13
  • 14. 150 100 50 50 100 150 150 100 50 50 100 150 14 UlamFinal.nb
  • 15. The number of primes in the range 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 to 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 010 000 is 4 The average probability of finding a prime in this range is 0.0004 UlamFinal.nb 15
  • 16. 40 20 20 40 40 20 20 40 9.922618282587337`*^-16 , True Built in prime test for 32416187567 1.1229999999999967` , True Naive prime test for 32416187567 6.543376951384516`*^-15 , True Fermat prime test with 10 attempts, for 32416187567 0.4520000000000069` , True Fermat prime test with 1,000 attempts, for 32416187567 4.289999999999993` , True Fermat prime test with 10,000 attempts, for 32416187567 0.016000000000005718` , Null Built in prime test for all the numbers between 1000000 and 1010000 6.598999999999997` , Null Naive prime test for all the numbers between 1000000 and 1010000 3.9310000000000063` , Null Fermat prime test with 10 attempts, for all the numbers between 1000000 and 1010000 16 UlamFinal.nb
  • 17. 19.921000000000006` , Null Fermat prime test with 100 attempts, for all the numbers between 1000000 and 1010000 0.015999999999988926` , Null Built in prime test for all the numbers between 100000000 and 100010000 4.8520000000000065` , Null Fermat prime test with 10 attempts, for all the numbers between 100000000 and 100010000 20.716999999999988` , Null Fermat prime test with 100 attempts, for all the numbers between 100000000 and 100010000 UlamFinal.nb 17