Ok, major upgrade.
I figured out how to do away with using|iterating over k values. I explain the process in the updated paper, which has this updated, orders-of-magnitude faster code.
require "big"
require "primes-utils" # provides ‘prime?'
def mpg(p, m) mp = (1.to_big_i << (p + m)) - 1 end
p = ARGV.size > 0 ? (ARGV[0].to_u64 underscore: true) : 3u64
m = 2u64
tm = Time.instant
puts "Starting search for next Mp with known p = #{p}"
loop do
mp = mpg(p, m)
if mp.prime?
p = (Math.log(mp + 1)/Math.log(2)).to_u64
pp [p, m, mp]
puts "Elapsed time = #{Time.instant - tm }"
puts "\nStarting search for next Mp with known p = #{p}\n"
m = 2u64
tm = Time.instant
else
m += 2
end
end
It now produces scarily
fast times.
➜ ./mpgs
Starting search for next Mp with known p = 3
[5, 2, 31]
Elapsed time = 00:00:00.000057178
Starting search for next Mp with known p = 5
[7, 2, 127]
Elapsed time = 00:00:00.000024556
Starting search for next Mp with known p = 7
[13, 6, 8191]
Elapsed time = 00:00:00.000020819
Starting search for next Mp with known p = 13
[17, 4, 131071]
Elapsed time = 00:00:00.000026760
Starting search for next Mp with known p = 17
[19, 2, 524287]
Elapsed time = 00:00:00.000022142
Starting search for next Mp with known p = 19
[31, 12, 2147483647]
Elapsed time = 00:00:00.000028463
Starting search for next Mp with known p = 31
[61, 30, 2305843009213693951]
Elapsed time = 00:00:00.000046226
Starting search for next Mp with known p = 61
[89, 28, 618970019642690137449562111]
Elapsed time = 00:00:00.000059962
Starting search for next Mp with known p = 89
[107, 18, 162259276829213363391578010288127]
Elapsed time = 00:00:00.000050865
Starting search for next Mp with known p = 107
[127, 20, 170141183460469231731687303715884105727]
Elapsed time = 00:00:00.000048701
Starting search for next Mp with known p = 127
[521, 394, 6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151]
Elapsed time = 00:00:00.002608888
Starting search for next Mp with known p = 521
[607, 86, 531137992816767098689588206552468627329593117727031923199444138200403559860852242739162502265229285668889329486246501015346579337652707239409519978766587351943831270835393219031728127]
Elapsed time = 00:00:00.002203116
Starting search for next Mp with known p = 607
Unhandled exception: Arithmetic overflow (OverflowError)
from /home/jzakiya/crystal/share/crystal/src/crystal/system/unix/time.cr:44:35 in '__crystal_main'
from /home/jzakiya/crystal/share/crystal/src/crystal/at_exit_handlers.cr:21:26 in 'main'
from /home/jzakiya/crystal/share/crystal/src/crystal/system/unix/main.cr:10:3 in 'main'
from /lib/x86_64-linux-gnu/libc.so.6 in '??'
from /lib/x86_64-linux-gnu/libc.so.6 in '__libc_start_main'
from ./mpgs1 in '_start'
from ???
➜ mps
You see it only stopped because of the limitations of the software to continue processing the large numbers using p = 607. So now the algorithm|code is no longer time limited, but is software limited. If that can be resolved in Crystal I can find a new largest Mp by next week, since it’s now so fast. 