prime_miller_rabin 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +145 -215
- data/lib/prime_miller_rabin/version.rb +1 -2
- data/lib/prime_miller_rabin.rb +3 -45
- metadata +22 -37
- data/.gitignore +0 -17
- data/prime_miller_rabin.gemspec +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 370adffee7ec8bd59772367385f369ccbe4a399ff9385ce8e01f6482d6172ae7
|
4
|
+
data.tar.gz: b27039c007ba06f4d7eeb5504114a275370b8b9f32de5341902473a31259aae0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab6d6c51cee70972173ab3ef9c9ef07323bfa39c6ffc25e53341d2f6d952848c016d74d00c72cbda5617cafc78de44ecd67de5525c78e83f002891a2954a09cb
|
7
|
+
data.tar.gz: 9e2bb05e9d95c148da51d3a46f4df012e968eb16b2c418ceb91941c950c4f73558298063d6f71fd1e7e533c727819cc619390c825e48cd97da7d36a83a43ab6e
|
data/README.md
CHANGED
@@ -14,216 +14,154 @@ and
|
|
14
14
|
|
15
15
|
The following code was used to compare Miller-Rabin with the existing Ruby Prime Generators:
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
17
|
+
require 'prime_miller_rabin'
|
18
|
+
require 'benchmark'
|
19
|
+
|
20
|
+
primes = load_primes() # Load primes from an external source
|
21
|
+
|
22
|
+
Prime::MillerRabin.speed_intercept
|
23
|
+
|
24
|
+
generators = {
|
25
|
+
MillerRabin: Prime::MillerRabin.new,
|
26
|
+
Generator23: Prime::Generator23.new,
|
27
|
+
Eratosthenes: Prime::EratosthenesGenerator.new,
|
28
|
+
TrialDivision: Prime::TrialDivisionGenerator.new
|
29
|
+
}
|
30
|
+
|
31
|
+
padding = ''
|
32
|
+
column_width = generators.keys.map(&:size).max
|
33
|
+
puts(generators.keys.map { |name| '%-*s' % [column_width, name] }.join('') + ' Number Tested')
|
34
|
+
|
35
|
+
time_limit = 120
|
36
|
+
|
37
|
+
primes.each_with_index do |number|
|
38
|
+
timings = generators.map { |name, generator| [name, Benchmark.measure { Prime.prime?(number, generator) }.total] }.to_h
|
39
|
+
puts timings.values.map { |x| '%-*.6f' % [column_width, x] }.push(padding).push(number).join(' ')
|
40
|
+
generators = generators.delete_if do |name, _|
|
41
|
+
if timings[name] > time_limit
|
42
|
+
puts "Removing #{name} as it is now exceeding #{time_limit / 60} minutes to determine primality."
|
43
|
+
padding += ' ' * (column_width + 1)
|
38
44
|
end
|
39
|
-
timings << benchmark.total
|
40
|
-
else
|
41
|
-
timings << nil
|
42
45
|
end
|
43
46
|
end
|
44
|
-
timings.map! { |x| x ? '%-15.6f' % [x] : '%15s' % [' '] }
|
45
|
-
timings << number
|
46
|
-
puts timings.join(' ')
|
47
|
-
generators.map! { |x| remove.include?(x) ? nil : x }
|
48
|
-
end
|
49
|
-
|
50
|
-
####The results (formatted for readability):
|
51
|
-
MillerRabin Generator23 Eratosthenes TrialDivision Number Tested
|
52
|
-
0.000000 0.000000 0.000000 0.000000 2
|
53
|
-
0.000000 0.000000 0.000000 0.000000 7
|
54
|
-
0.000000 0.000000 0.000000 0.000000 67
|
55
|
-
0.000000 0.000000 0.000000 0.000000 619
|
56
|
-
0.000000 0.000000 0.000000 0.000000 6197
|
57
|
-
0.000000 0.000000 0.000000 0.000000 61813
|
58
|
-
0.000000 0.000000 0.000000 0.000000 618041
|
59
|
-
0.000000 0.000000 0.010000 0.000000 6180341
|
60
|
-
0.000000 0.000000 0.000000 0.010000 61803419
|
61
|
-
0.000000 0.000000 0.020000 0.030000 618034003
|
62
|
-
0.000000 0.010000 0.050000 0.120000 6180339923
|
63
|
-
0.000000 0.040000 0.220000 1.690000 61803398903
|
64
|
-
0.000000 0.140000 0.990000 13.080000 618033988751
|
65
|
-
0.010000 0.390000 4.110000 119.750000 6180339887543
|
66
|
-
Removing TrialDivision as it is now exceeding 2 minutes to determine primality
|
67
|
-
0.000000 1.820000 30.460000 1081.650000 61803398875019
|
68
|
-
Removing Eratosthenes as it is now exceeding 2 minutes to determine primality
|
69
|
-
0.000000 7.180000 139.250000 618033988749911
|
70
|
-
0.010000 16.990000 6180339887498971
|
71
|
-
0.000000 53.850000 61803398874989489
|
72
|
-
Removing Generator23 as it is now exceeding 2 minutes to determine primality
|
73
|
-
0.010000 170.560000 618033988749894811
|
74
|
-
|
75
|
-
MillerRabin Number Tested
|
76
|
-
0.000000 6180339887498948681
|
77
|
-
0.000000 61803398874989486159
|
78
|
-
0.000000 618033988749894877249
|
79
|
-
0.000000 6180339887498948771861
|
80
|
-
0.020000 61803398874989479329793
|
81
|
-
0.000000 618033988749894843629693
|
82
|
-
0.010000 6180339887498948973166649
|
83
|
-
0.000000 61803398874989485436698673
|
84
|
-
0.000000 618033988749894820007248007
|
85
|
-
0.020000 6180339887498948474950385857
|
86
|
-
0.000000 61803398874989473754387579003
|
87
|
-
0.000000 618033988749894825504806010893
|
88
|
-
0.010000 6180339887498947551360618332249
|
89
|
-
0.020000 61803398874989482269005624377351
|
90
|
-
0.000000 618033988749894786661259224809529
|
91
|
-
0.010000 6180339887498948010727780323950599
|
92
|
-
0.020000 61803398874989484718963821666894041
|
93
|
-
0.000000 618033988749894884083126364088041501
|
94
|
-
0.010000 6180339887498948102961500692498350149
|
95
|
-
0.020000 61803398874989478668431765490160893959
|
96
|
-
0.000000 618033988749894805573783586380189794451
|
97
|
-
0.010000 6180339887498948055737835863801897943079
|
98
|
-
0.020000 61803398874989485393081637096535678255353
|
99
|
-
0.010000 618033988749894834588003257131289987252251
|
100
|
-
0.000000 6180339887498947881652517839295296785350671
|
101
|
-
0.020000 61803398874989486244165414105234617248252037
|
102
|
-
0.010000 618033988749894783213491626788008578938568879
|
103
|
-
0.020000 6180339887498948782872866439052136911913091139
|
104
|
-
0.010000 61803398874989490364029864846980172112537321529
|
105
|
-
0.020000 618033988749894863075479441166460873230870642701
|
106
|
-
0.010000 6180339887498948306236240753237881949152685850683
|
107
|
-
0.020000 61803398874989488254659266067206448022023187726371
|
108
|
-
0.010000 618033988749894861777405226532753966098246560383039
|
109
|
-
0.020000 6180339887498948285467053319098571435030700533743709
|
110
|
-
0.010000 61803398874989477537758550051322222735078764216058197
|
111
|
-
0.030000 618033988749894860448177230747838093194439500102631463
|
112
|
-
0.000000 6180339887498948264199405386539917468569787569258103079
|
113
|
-
0.030000 61803398874989493531029795335430005513685313509163794507
|
114
|
-
0.010000 618033988749894848198012021594053408512953632558975811599
|
115
|
-
0.020000 6180339887498947959306404625379054205386139310393785319457
|
116
|
-
0.010000 61803398874989483774453770978282381091808569225505635565881
|
117
|
-
0.030000 618033988749894815443792511252200669382367419606694849675361
|
118
|
-
0.020000 6180339887498947619220040347787051296966435652506272353222859
|
119
|
-
0.010000 61803398874989487610181945125549561435952112121023814594199579
|
120
|
-
0.030000 618033988749894876101819451255495614359521121210238145941995523
|
121
|
-
0.030000 6180339887498948212955080513466361817213398943496249088445251857
|
122
|
-
0.010000 61803398874989482129550805134663618172133989434962490884452515863
|
123
|
-
0.030000 618033988749894751143429459463296107944467923968039965359763095659
|
124
|
-
0.020000 6180339887498948446795342486410828729802972178101532233394458460333
|
125
|
-
0.020000 61803398874989478481642718356729934335736646975120073823244888571933
|
126
|
-
0.030000 618033988749894856652155661655839578904883367421943720360845238075493
|
127
|
-
0.030000 6180339887498948949645441833030610378635590461796733108293232926654757
|
128
|
-
0.010000 61803398874989480301481173134972953636273741716112229370497596164931657
|
129
|
-
0.030000 618033988749894753974954423641286068895632548351228417905324051774046223
|
130
|
-
0.030000 6180339887498948520546690390581730038298422859710161695046278715245855121
|
131
|
-
0.030000 61803398874989478928365168519136536547194805389435200848107342688424034467
|
132
|
-
0.030000 618033988749894789283651685191365365471948053894352008481073426884240343509
|
133
|
-
0.030000 6180339887498948294571027916661222540210003624234170715361482714540612255771
|
134
|
-
0.030000 61803398874989487766524411943583052027986313265829514720223808493784628461601
|
135
|
-
0.030000 618033988749894800532217995004297294265682700282490226136494383363790190149697
|
136
|
-
0.030000 6180339887498948416698319280344483481399122642162528507048910242032867738649237
|
137
|
-
0.020000 61803398874989489103496864767062961278898774093676800018696699321068267432312833
|
138
|
-
0.030000 618033988749894759394604061974146240391453136348727601568097742524293606434406857
|
139
|
-
0.030000 6180339887498947804570623956855835799750586730828140653471168226341158572966019139
|
140
|
-
0.030000 61803398874989483100696239659303319497571196124462157841676261489768925936587112561
|
141
|
-
0.040000 618033988749894911886802398044952578976757222303513599328195882519406702676701872319
|
142
|
-
0.030000 6180339887498948040470157294423934003086968742249909047796181923571167782622608752829
|
143
|
-
0.040000 61803398874989482130138159641880286889558652991755453590739062278308316616857143476423
|
144
|
-
0.040000 618033988749894793694396209256547719156563080809452726102954734101536945518474539565289
|
145
|
-
0.040000 6180339887498948378655728287161559587390005993824156217900521559920108985586295718806271
|
146
|
-
0.040000 61803398874989483786557282871615595873900059938241562179005215599201089855862957188055087
|
147
|
-
0.030000 618033988749894837865572828716155958739000599382415621790052155992010898558629571880550497
|
148
|
-
0.020000 6180339887498948830968576870427947960714166184011296269736399160078562264717483249716166887
|
149
|
-
0.040000 61803398874989484691182980038148372620548380318615842282676970799517996414125332249876365411
|
150
|
-
0.030000 618033988749894890333863264375057010044603181444123867803013957610391478937847325466187268189
|
151
|
-
0.040000 6180339887498947977001918745221006711878151744937975851870262250979402473717801191356835561549
|
152
|
-
0.050000 61803398874989483475366043046328320673053037727392809823342131810292073999820700166788504093107
|
153
|
-
0.040000 618033988749894819932273008086810192513444296161875893014863280900928542947636248655004447015003
|
154
|
-
0.030000 6180339887498948673607127596915238380081197557204429497142489999473035735094626582962223475327741
|
155
|
-
0.040000 61803398874989482941796095840775292161237938807358930435474042471020354906000153058324802711846941
|
156
|
-
0.030000 618033988749894799063759517380736188495787093956106388067133564520523529500432628412868570787086393
|
157
|
-
0.040000 6180339887498948233471206702023495749890609292500927210972190526722675451480877501491721358521925753
|
158
|
-
|
159
|
-
|
160
|
-
####Larger numbers
|
161
|
-
|
162
|
-
For primes nearing a googol (10**100) it is still subsecond.
|
163
|
-
Starting at a google - 3 the following was used for benchmarking,
|
164
|
-
|
165
|
-
Benchmark.bm do |x|
|
166
|
-
(1..50).each do |z|
|
167
|
-
exponent = "#{z}00".to_i
|
168
|
-
number = 10**exponent - 3
|
169
|
-
x.report("10**#{exponent} - 3") { number.prime? }
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
####Results (formatted for readability)
|
174
|
-
|
175
|
-
user system total real
|
176
|
-
10**100 - 3 0.000000 0.000000 0.000000 ( 0.000873)
|
177
|
-
10**200 - 3 0.000000 0.000000 0.000000 ( 0.003954)
|
178
|
-
10**300 - 3 0.010000 0.000000 0.010000 ( 0.008990)
|
179
|
-
10**400 - 3 0.020000 0.000000 0.020000 ( 0.019595)
|
180
|
-
10**500 - 3 0.030000 0.000000 0.030000 ( 0.030311)
|
181
|
-
10**600 - 3 0.050000 0.000000 0.050000 ( 0.045907)
|
182
|
-
10**700 - 3 0.080000 0.010000 0.090000 ( 0.086039)
|
183
|
-
10**800 - 3 0.120000 0.000000 0.120000 ( 0.120604)
|
184
|
-
10**900 - 3 0.140000 0.000000 0.140000 ( 0.137074)
|
185
|
-
10**1000 - 3 0.190000 0.000000 0.190000 ( 0.197226)
|
186
|
-
10**1100 - 3 0.270000 0.010000 0.280000 ( 0.267312)
|
187
|
-
10**1200 - 3 0.340000 0.000000 0.340000 ( 0.344282)
|
188
|
-
10**1300 - 3 0.370000 0.000000 0.370000 ( 0.376330)
|
189
|
-
10**1400 - 3 0.520000 0.010000 0.530000 ( 0.530934)
|
190
|
-
10**1500 - 3 0.610000 0.010000 0.620000 ( 0.622023)
|
191
|
-
10**1600 - 3 0.810000 0.010000 0.820000 ( 0.817583)
|
192
|
-
10**1700 - 3 0.910000 0.010000 0.920000 ( 0.917380)
|
193
|
-
10**1800 - 3 1.050000 0.010000 1.060000 ( 1.071910)
|
194
|
-
10**1900 - 3 1.180000 0.020000 1.200000 ( 1.189116)
|
195
|
-
10**2000 - 3 1.410000 0.020000 1.430000 ( 1.438527)
|
196
|
-
10**2100 - 3 1.480000 0.020000 1.500000 ( 1.499630)
|
197
|
-
10**2200 - 3 1.820000 0.030000 1.850000 ( 1.838164)
|
198
|
-
10**2300 - 3 2.000000 0.030000 2.030000 ( 2.026655)
|
199
|
-
10**2400 - 3 1.970000 0.020000 1.990000 ( 1.997051)
|
200
|
-
10**2500 - 3 2.580000 0.040000 2.620000 ( 2.616159)
|
201
|
-
10**2600 - 3 3.060000 0.050000 3.110000 ( 3.110208)
|
202
|
-
10**2700 - 3 2.900000 0.050000 2.950000 ( 2.950306)
|
203
|
-
10**2800 - 3 2.900000 0.050000 2.950000 ( 2.945470)
|
204
|
-
10**2900 - 3 3.310000 0.050000 3.360000 ( 3.360690)
|
205
|
-
10**3000 - 3 3.700000 0.070000 3.770000 ( 3.765682)
|
206
|
-
10**3100 - 3 4.610000 0.070000 4.680000 ( 4.680919)
|
207
|
-
10**3200 - 3 5.530000 0.080000 5.610000 ( 5.615243)
|
208
|
-
10**3300 - 3 4.770000 0.090000 4.860000 ( 4.860779)
|
209
|
-
10**3400 - 3 5.190000 0.090000 5.280000 ( 5.278715)
|
210
|
-
10**3500 - 3 5.800000 0.100000 5.900000 ( 5.891275)
|
211
|
-
10**3600 - 3 6.310000 0.110000 6.420000 ( 6.417548)
|
212
|
-
10**3700 - 3 8.450000 0.070000 8.520000 ( 8.510452)
|
213
|
-
10**3800 - 3 8.830000 0.070000 8.900000 ( 8.901605)
|
214
|
-
10**3900 - 3 8.040000 0.080000 8.120000 ( 8.114340)
|
215
|
-
10**4000 - 3 10.030000 0.050000 10.080000 ( 10.087971)
|
216
|
-
10**4100 - 3 8.730000 0.060000 8.790000 ( 8.782747)
|
217
|
-
10**4200 - 3 11.550000 0.070000 11.620000 ( 11.607290)
|
218
|
-
10**4300 - 3 10.810000 0.100000 10.910000 ( 10.913006)
|
219
|
-
10**4400 - 3 12.380000 0.180000 12.560000 ( 12.552739)
|
220
|
-
10**4500 - 3 12.580000 0.180000 12.760000 ( 12.753963)
|
221
|
-
10**4600 - 3 13.130000 0.190000 13.320000 ( 13.311686)
|
222
|
-
10**4700 - 3 14.380000 0.190000 14.570000 ( 14.560988)
|
223
|
-
10**4800 - 3 13.680000 0.220000 13.900000 ( 13.895690)
|
224
|
-
10**4900 - 3 15.800000 0.220000 16.020000 ( 16.017528)
|
225
|
-
10**5000 - 3 15.290000 0.230000 15.520000 ( 15.513277)
|
226
47
|
|
48
|
+
#### The results (formatted for readability):
|
49
|
+
|
50
|
+
| MillerRabin | Generator23 | Eratosthenes | TrialDivision | Number Tested |
|
51
|
+
|------------:|------------:|-------------:|--------------:|:---------------|
|
52
|
+
| 0.000 | 0.000 | 0.000 | 0.000 | 2 |
|
53
|
+
| 0.000 | 0.000 | 0.000 | 0.000 | 7 |
|
54
|
+
| 0.000 | 0.000 | 0.000 | 0.000 | 67 |
|
55
|
+
| 0.000 | 0.000 | 0.000 | 0.000 | 619 |
|
56
|
+
| 0.000 | 0.000 | 0.000 | 0.000 | 6197 |
|
57
|
+
| 0.000 | 0.000 | 0.000 | 0.000 | 61813 |
|
58
|
+
| 0.000 | 0.000 | 0.000 | 0.000 | 618041 |
|
59
|
+
| 0.000 | 0.000 | 0.000 | 0.000 | 6180341 |
|
60
|
+
| 0.000 | 0.000 | 0.000 | 0.000 | 61803419 |
|
61
|
+
| 0.000 | 0.000 | 0.015 | 0.016 | 618034003 |
|
62
|
+
| 0.000 | 0.015 | 0.016 | 0.141 | 6180339923 |
|
63
|
+
| 0.000 | 0.015 | 0.031 | 1.079 | 61803398903 |
|
64
|
+
| 0.015 | 0.063 | 0.047 | 6.500 | 618033988751 |
|
65
|
+
| 0.000 | 0.156 | 0.187 | 64.657 | 6180339887543 |
|
66
|
+
| 0.000 | 0.484 | 0.656 | 631.251 | 61803398875019 |
|
67
|
+
|
68
|
+
#### Removing TrialDivision as it is now exceeding 2 minutes to determine primality
|
69
|
+
|
70
|
+
| MillerRabin | Generator23 | Eratosthenes | Number Tested |
|
71
|
+
|------------:|------------:|-------------:|:---------------------|
|
72
|
+
| 0.000 | 1.578 | 1.905 | 618033988749911 |
|
73
|
+
| 0.000 | 4.828 | 5.938 | 6180339887498971 |
|
74
|
+
| 0.000 | 15.219 | 20.453 | 61803398874989489 |
|
75
|
+
| 0.000 | 51.344 | 78.500 | 618033988749894811 |
|
76
|
+
| 0.000 | 199.203 | 604.875 | 6180339887498948681 |
|
77
|
+
|
78
|
+
#### Removing Generator23 as it is now exceeding 2 minutes to determine primality
|
79
|
+
#### Removing Eratosthenes as it is now exceeding 2 minutes to determine primality
|
80
|
+
|
81
|
+
| MillerRabin | Number Tested |
|
82
|
+
|-------------|-------------------------------------------------------------------------------------------------------|
|
83
|
+
| 0.000 | 61803398874989486159 |
|
84
|
+
| 0.000 | 618033988749894877249 |
|
85
|
+
| 0.000 | 6180339887498948771861 |
|
86
|
+
| 0.000 | 61803398874989479329793 |
|
87
|
+
| 0.000 | 618033988749894843629693 |
|
88
|
+
| 0.000 | 6180339887498948973166649 |
|
89
|
+
| 0.000 | 61803398874989485436698673 |
|
90
|
+
| 0.016 | 618033988749894820007248007 |
|
91
|
+
| 0.000 | 6180339887498948474950385857 |
|
92
|
+
| 0.000 | 61803398874989473754387579003 |
|
93
|
+
| 0.000 | 618033988749894825504806010893 |
|
94
|
+
| 0.000 | 6180339887498947551360618332249 |
|
95
|
+
| 0.000 | 61803398874989482269005624377351 |
|
96
|
+
| 0.000 | 618033988749894786661259224809529 |
|
97
|
+
| 0.000 | 6180339887498948010727780323950599 |
|
98
|
+
| 0.000 | 61803398874989484718963821666894041 |
|
99
|
+
| 0.000 | 618033988749894884083126364088041501 |
|
100
|
+
| 0.015 | 6180339887498948102961500692498350149 |
|
101
|
+
| 0.000 | 61803398874989478668431765490160893959 |
|
102
|
+
| 0.000 | 618033988749894805573783586380189794451 |
|
103
|
+
| 0.000 | 6180339887498948055737835863801897943079 |
|
104
|
+
| 0.016 | 61803398874989485393081637096535678255353 |
|
105
|
+
| 0.000 | 618033988749894834588003257131289987252251 |
|
106
|
+
| 0.000 | 6180339887498947881652517839295296785350671 |
|
107
|
+
| 0.000 | 61803398874989486244165414105234617248252037 |
|
108
|
+
| 0.016 | 618033988749894783213491626788008578938568879 |
|
109
|
+
| 0.000 | 6180339887498948782872866439052136911913091139 |
|
110
|
+
| 0.000 | 61803398874989490364029864846980172112537321529 |
|
111
|
+
| 0.000 | 618033988749894863075479441166460873230870642701 |
|
112
|
+
| 0.016 | 6180339887498948306236240753237881949152685850683 |
|
113
|
+
| 0.000 | 61803398874989488254659266067206448022023187726371 |
|
114
|
+
| 0.000 | 618033988749894861777405226532753966098246560383039 |
|
115
|
+
| 0.000 | 6180339887498948285467053319098571435030700533743709 |
|
116
|
+
| 0.015 | 61803398874989477537758550051322222735078764216058197 |
|
117
|
+
| 0.000 | 618033988749894860448177230747838093194439500102631463 |
|
118
|
+
| 0.000 | 6180339887498948264199405386539917468569787569258103079 |
|
119
|
+
| 0.016 | 61803398874989493531029795335430005513685313509163794507 |
|
120
|
+
| 0.000 | 618033988749894848198012021594053408512953632558975811599 |
|
121
|
+
| 0.000 | 6180339887498947959306404625379054205386139310393785319457 |
|
122
|
+
| 0.015 | 61803398874989483774453770978282381091808569225505635565881 |
|
123
|
+
| 0.000 | 618033988749894815443792511252200669382367419606694849675361 |
|
124
|
+
| 0.016 | 6180339887498947619220040347787051296966435652506272353222859 |
|
125
|
+
| 0.000 | 61803398874989487610181945125549561435952112121023814594199579 |
|
126
|
+
| 0.015 | 618033988749894876101819451255495614359521121210238145941995523 |
|
127
|
+
| 0.000 | 6180339887498948212955080513466361817213398943496249088445251857 |
|
128
|
+
| 0.016 | 61803398874989482129550805134663618172133989434962490884452515863 |
|
129
|
+
| 0.000 | 618033988749894751143429459463296107944467923968039965359763095659 |
|
130
|
+
| 0.016 | 6180339887498948446795342486410828729802972178101532233394458460333 |
|
131
|
+
| 0.000 | 61803398874989478481642718356729934335736646975120073823244888571933 |
|
132
|
+
| 0.015 | 618033988749894856652155661655839578904883367421943720360845238075493 |
|
133
|
+
| 0.016 | 6180339887498948949645441833030610378635590461796733108293232926654757 |
|
134
|
+
| 3.984 | 61803398874989480301481173134972953636273741716112229370497596164931657 |
|
135
|
+
| 0.016 | 618033988749894753974954423641286068895632548351228417905324051774046223 |
|
136
|
+
| 0.016 | 6180339887498948520546690390581730038298422859710161695046278715245855121 |
|
137
|
+
| 0.015 | 61803398874989478928365168519136536547194805389435200848107342688424034467 |
|
138
|
+
| 0.016 | 618033988749894789283651685191365365471948053894352008481073426884240343509 |
|
139
|
+
| 0.015 | 6180339887498948294571027916661222540210003624234170715361482714540612255771 |
|
140
|
+
| 0.016 | 61803398874989487766524411943583052027986313265829514720223808493784628461601 |
|
141
|
+
| 0.000 | 618033988749894800532217995004297294265682700282490226136494383363790190149697 |
|
142
|
+
| 0.016 | 6180339887498948416698319280344483481399122642162528507048910242032867738649237 |
|
143
|
+
| 0.015 | 61803398874989489103496864767062961278898774093676800018696699321068267432312833 |
|
144
|
+
| 0.000 | 618033988749894759394604061974146240391453136348727601568097742524293606434406857 |
|
145
|
+
| 0.016 | 6180339887498947804570623956855835799750586730828140653471168226341158572966019139 |
|
146
|
+
| 0.016 | 61803398874989483100696239659303319497571196124462157841676261489768925936587112561 |
|
147
|
+
| 0.015 | 618033988749894911886802398044952578976757222303513599328195882519406702676701872319 |
|
148
|
+
| 0.016 | 6180339887498948040470157294423934003086968742249909047796181923571167782622608752829 |
|
149
|
+
| 0.016 | 61803398874989482130138159641880286889558652991755453590739062278308316616857143476423 |
|
150
|
+
| 0.015 | 618033988749894793694396209256547719156563080809452726102954734101536945518474539565289 |
|
151
|
+
| 0.016 | 6180339887498948378655728287161559587390005993824156217900521559920108985586295718806271 |
|
152
|
+
| 0.016 | 61803398874989483786557282871615595873900059938241562179005215599201089855862957188055087 |
|
153
|
+
| 0.015 | 618033988749894837865572828716155958739000599382415621790052155992010898558629571880550497 |
|
154
|
+
| 0.016 | 6180339887498948830968576870427947960714166184011296269736399160078562264717483249716166887 |
|
155
|
+
| 0.016 | 61803398874989484691182980038148372620548380318615842282676970799517996414125332249876365411 |
|
156
|
+
| 0.015 | 618033988749894890333863264375057010044603181444123867803013957610391478937847325466187268189 |
|
157
|
+
| 0.016 | 6180339887498947977001918745221006711878151744937975851870262250979402473717801191356835561549 |
|
158
|
+
| 0.031 | 61803398874989483475366043046328320673053037727392809823342131810292073999820700166788504093107 |
|
159
|
+
| 0.016 | 618033988749894819932273008086810192513444296161875893014863280900928542947636248655004447015003 |
|
160
|
+
| 0.015 | 6180339887498948673607127596915238380081197557204429497142489999473035735094626582962223475327741 |
|
161
|
+
| 0.016 | 61803398874989482941796095840775292161237938807358930435474042471020354906000153058324802711846941 |
|
162
|
+
| 0.015 | 618033988749894799063759517380736188495787093956106388067133564520523529500432628412868570787086393 |
|
163
|
+
| 0.016 | 6180339887498948233471206702023495749890609292500927210972190526722675451480877501491721358521925753 |
|
164
|
+
| 0.015 | 61803398874989482334712067020234957498906092925009272109721905267226754514808775014917213585219257561 |
|
227
165
|
|
228
166
|
## Installation
|
229
167
|
|
@@ -252,12 +190,4 @@ Or install it yourself as:
|
|
252
190
|
Prime::MillerRabin.speed_intercept
|
253
191
|
|
254
192
|
# To use the speed intercept and have Miller Rabin be the default prime generator in all cases use:
|
255
|
-
Prime::MillerRabin.make_default
|
256
|
-
|
257
|
-
## Contributing
|
258
|
-
|
259
|
-
1. Fork it
|
260
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
261
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
262
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
263
|
-
5. Create new Pull Request
|
193
|
+
Prime::MillerRabin.make_default
|
data/lib/prime_miller_rabin.rb
CHANGED
@@ -1,57 +1,15 @@
|
|
1
|
-
require 'backports' if RUBY_VERSION < '1.9'
|
2
1
|
require 'prime'
|
3
2
|
require "prime_miller_rabin/version"
|
4
3
|
|
5
4
|
class Prime::MillerRabin < Prime::PseudoPrimeGenerator
|
6
5
|
|
7
6
|
def self.speed_intercept
|
8
|
-
|
9
|
-
Prime.send(:prepend, Prime::MillerRabin::PrimeIntercept)
|
10
|
-
else
|
11
|
-
Prime.class_eval <<-INTERCEPT_EVAL, __FILE__, __LINE__ + 1
|
12
|
-
def prime_with_intercept?(value, *args)
|
13
|
-
args.first.instance_of?(Prime::MillerRabin) ? args.first.prime?(value) : prime_without_intercept?(value, *args)
|
14
|
-
end
|
15
|
-
|
16
|
-
alias_method "prime_without_intercept?", "prime?"
|
17
|
-
alias_method "prime?", "prime_with_intercept?"
|
18
|
-
INTERCEPT_EVAL
|
19
|
-
end
|
7
|
+
Prime.send(:prepend, Prime::MillerRabin::PrimeIntercept)
|
20
8
|
end
|
21
9
|
|
22
10
|
def self.make_default
|
23
|
-
|
24
|
-
|
25
|
-
Integer.send(:prepend, Prime::MillerRabin::Default::Integer)
|
26
|
-
else
|
27
|
-
Prime.class_eval <<-PRIME_DEFAULT_EVAL, __FILE__, __LINE__ + 1
|
28
|
-
# Change the default generator used to be MillerRabin
|
29
|
-
def prime_with_mr_default?(value, generator = ::Prime::MillerRabin.new)
|
30
|
-
generator.instance_of?(Prime::MillerRabin) ? generator.prime?(value) : prime_without_mr_default?(value, generator)
|
31
|
-
end
|
32
|
-
|
33
|
-
def prime_division_with_mr_default?(value, generator = ::Prime::MillerRabin.new)
|
34
|
-
prime_division_without_mr_default?(value, generator)
|
35
|
-
end
|
36
|
-
|
37
|
-
alias_method "prime_without_mr_default?", "prime?"
|
38
|
-
alias_method "prime?", "prime_with_mr_default?"
|
39
|
-
|
40
|
-
alias_method "prime_division_without_mr_default?", "prime_division"
|
41
|
-
alias_method "prime_division", "prime_division_with_mr_default?"
|
42
|
-
PRIME_DEFAULT_EVAL
|
43
|
-
|
44
|
-
Integer.class_eval <<-INTEGER_DEFAULT_EVAL, __FILE__, __LINE__ + 1
|
45
|
-
|
46
|
-
def prime_division_with_mr_default(generator = ::Prime::MillerRabin.new)
|
47
|
-
prime_division_without_mr_default(generator)
|
48
|
-
end
|
49
|
-
|
50
|
-
alias_method "prime_division_with_mr_default?", "prime_division"
|
51
|
-
alias_method "prime_division", "prime_division_with_mr_default?"
|
52
|
-
INTEGER_DEFAULT_EVAL
|
53
|
-
|
54
|
-
end
|
11
|
+
Prime.send(:prepend, Prime::MillerRabin::Default::Prime, Prime::MillerRabin::PrimeIntercept)
|
12
|
+
Integer.send(:prepend, Prime::MillerRabin::Default::Integer)
|
55
13
|
end
|
56
14
|
|
57
15
|
def succ()
|
metadata
CHANGED
@@ -1,57 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prime_miller_rabin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Hall
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: backports
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
|
-
- - ~>
|
17
|
+
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
19
|
+
version: '2.3'
|
34
20
|
type: :development
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - ~>
|
24
|
+
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
26
|
+
version: '2.3'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- -
|
31
|
+
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
33
|
+
version: '13'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- -
|
38
|
+
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
40
|
+
version: '13'
|
55
41
|
description: Test primes faster than Ruby's default methods by using the Miller-Rabin
|
56
42
|
method.
|
57
43
|
email:
|
@@ -60,36 +46,35 @@ executables: []
|
|
60
46
|
extensions: []
|
61
47
|
extra_rdoc_files: []
|
62
48
|
files:
|
63
|
-
- .gitignore
|
64
49
|
- Gemfile
|
65
50
|
- LICENSE.txt
|
66
51
|
- README.md
|
67
52
|
- Rakefile
|
68
53
|
- lib/prime_miller_rabin.rb
|
69
54
|
- lib/prime_miller_rabin/version.rb
|
70
|
-
|
71
|
-
homepage: ''
|
55
|
+
homepage: https://github.com/ChapterHouse/prime_miller_rabin
|
72
56
|
licenses:
|
73
57
|
- MIT
|
74
|
-
metadata:
|
75
|
-
|
58
|
+
metadata:
|
59
|
+
homepage_uri: https://github.com/ChapterHouse/prime_miller_rabin
|
60
|
+
source_code_uri: https://github.com/ChapterHouse/prime_miller_rabin/tree/v0.1.0
|
61
|
+
post_install_message:
|
76
62
|
rdoc_options: []
|
77
63
|
require_paths:
|
78
64
|
- lib
|
79
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
80
66
|
requirements:
|
81
|
-
- -
|
67
|
+
- - ">="
|
82
68
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
69
|
+
version: 3.0.0
|
84
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
71
|
requirements:
|
86
|
-
- -
|
72
|
+
- - ">="
|
87
73
|
- !ruby/object:Gem::Version
|
88
74
|
version: '0'
|
89
75
|
requirements: []
|
90
|
-
|
91
|
-
|
92
|
-
signing_key:
|
76
|
+
rubygems_version: 3.2.32
|
77
|
+
signing_key:
|
93
78
|
specification_version: 4
|
94
79
|
summary: Test primes faster than Ruby's default methods by using the Miller-Rabin
|
95
80
|
method.
|
data/.gitignore
DELETED
data/prime_miller_rabin.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'prime_miller_rabin/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "prime_miller_rabin"
|
8
|
-
spec.version = Prime::MillerRabin::VERSION
|
9
|
-
spec.authors = ["Frank Hall"]
|
10
|
-
spec.email = ["ChapterHouse.Dune@gmail.com"]
|
11
|
-
spec.description = %q{Test primes faster than Ruby's default methods by using the Miller-Rabin method.}
|
12
|
-
spec.summary = %q{Test primes faster than Ruby's default methods by using the Miller-Rabin method.}
|
13
|
-
spec.homepage = ""
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_runtime_dependency "backports" # Wish this could be conditional. It is only used for ruby 1.8 for as long as I support it.
|
22
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
-
spec.add_development_dependency "rake"
|
24
|
-
end
|