-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmills_constant.sf
40 lines (27 loc) · 926 Bytes
/
mills_constant.sf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/ruby
# Generate the Mills primes and the Mills constant.
# Definition:
# a(0) = 2; a(n) is least prime > a(n-1)^3.
# Mills constant is M = a(n)^(3^(-n)).
# Then floor(M^(3^n)) is always prime, for n >= 0.
# OEIS sequences:
# https://oeis.org/A051254
# https://oeis.org/A108739
# See also:
# https://www.youtube.com/watch?v=6ltrPVPEwfo
# https://en.wikipedia.org/wiki/Mills%27_constant
define C = 3 # see also Legendre's conjecture
func nth_mills_prime(n) is cached {
n<=0 ? 2 : next_prime(__FUNC__(n-1)**C)
}
func mills_constant(n) {
nth_mills_prime(n).root(C**n)
}
var M = mills_constant(6)
say 5.of { M**(C**_) -> floor }
say 5.of { nth_mills_prime(_) }
say "\nMills constant M =~ #{M}"
__END__
[2, 11, 1361, 2521008887, 16022236204009818131831320183]
[2, 11, 1361, 2521008887, 16022236204009818131831320183]
Mills constant M =~ 2.22949477249159523572285223765557019347314904643