Approximating Brun's Constant
Brun's Constant is a number where the reciprocals of odd twin primes are added together.
As to date, there is no proof for the Twin Prime Conjecture and it remains open.
So, Brun's Constant may be represented as an infinite sequence.
Recall that a twin prime is a prime number that differs by 2 from another prime.
An example of a twin prime would be 17 and 19.
For all integers k > 1, we have that:
where a ≡ b (mod d) means that a - b is evenly divisible by d.
That is to say, a and b have the same residue when divided by d.
The double factorial, n!! is the product of the natural numbers less than or equal to n that have the same parity as n.
It can be proved that there exists a generalization of Wilson's Theorem for the double factorial case.
Raise both sides of the congruences to ther power of 4 to obtain:
For all odd primes p.
Perform the same operation of raising the power by 4 on Wilson's Theorem.
for all primes p.
Now, let k be an odd, positive, composite integer. By definition, there exist integers a, b > 1 such that k = ab.
Since k is odd, so are a and b. Therefore both exist in the sequence 1, 3, …, k - 2 and
For all odd integers, k > 1
Let the function f be defined with a single argument.
Let k, m, and j be initialized respectively as 3, 1, and 0.
(k - 2)!!)4 = 1!!4 = 1 = m. m = ((k - 2)!!)4
j is a float and is equal to:
(k - 4)!!)4 % (k - 2) / (k - 2).
While k < n, the right argument of
and will be evaulated.
j = ((k - 4)!!)4 % (k - 2) / (k - 2) j = 1/(k - 2) if k - 2 is prime and j = 0 if not
Since m % k = ((k - 2)!!)4 equals 1 if k is prime and 0 if not,
-m % k = k - 1
If k is prime and -m % k = 0 if not.
: 2(k - 1)/(k(k - 2)) = ((k - 2) + k)/(k(k - 2)) = 1/k + 1/(k - 2)
If the pair (k - 2, k) consists of twin primes and to 0 if not.
Now, add the result to the return value of the recursive call:
k increments by 2, therefore only taking odd values.
m is multiplied by k⁴, since
mk⁴ = ((k - 2)!!)⁴k⁴ = (k!!)⁴
Pass the current value of
m % k / k
which equals 1/k if the previous k is a prime and 0 if not – as parameter j to the function call.
Once k is equal to or greater than n, f will return False and stop
1/k + 1/(k - 2)
such that (k - 2, k) is a twin prime pair and k < n, as desired.
f=lambda n,k=3,m=1,j=0:k<n and-m%k*j*2/k+f(n,k+2,m*k**4,m%k/k)