Skip to content

@aks /Test-prime-pair-sums.ijs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Sum of Two Prime Numbers: If p, q > 2 are consecutive in set of primes. Since p,q can only be odd number, (p+q) is an even number. Can (p+q)/2 be prime? It appears not, as confirmed for the pairs of consecutive primes in first million primes. See the J program below.
i. 20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
NB. generate the first 20 primes
p: i. 20
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
NB. box up consecutive pairs of those primes
(2 <\ ]) p: i. 20
┌───┬───┬───┬────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
2 33 55 77 1111 1313 1717 1919 2323 2929 3131 3737 4141 4343 4747 5353 5959 6161 6767 71
└───┴───┴───┴────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
NB. sum up each pair of primes
+/ each (2 <\ ])p: i. 20
┌─┬─┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬───┬───┬───┬───┬───┐
58121824303642526068788490100112120128138
└─┴─┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴───┴───┴───┴───┴───┘
NB. divide each sum by 2
2 %~ each +/ each (2 <\ ])p: i. 20
┌───┬─┬─┬─┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
2.5469121518212630343942455056606469
└───┴─┴─┴─┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘
NB. now, test each of those results for being prime. 1 p: y -- tests y for being prime
1&p: each 2 %~ each +/ each (2 <\ ])p: i. 20
┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
0000000000000000000
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
NB. open the boxed results, so we can add them up
>1&p: each 2 %~ each +/ each (2 <\ ])p: i. 20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
NB. sum/reduce the vector of booleans. If there's a prime, the sum will be > 0
+/>1&p: each 2 %~ each +/ each (2 <\ ])p: i. 20
0
NB. ok. No primes. Let's keep checking for larger groups
+/>1&p: each 2 %~ each +/ each (2 <\ ])p: i. 1000
0
+/>1&p: each 2 %~ each +/ each (2 <\ ])p: i. 10000
0
+/>1&p: each 2 %~ each +/ each (2 <\ ])p: i. 100000
0
NB. the previous output took a few seconds. The next will take a few minutes
+/>1&p: each 2 %~ each +/ each (2 <\ ])p: i. 1000000
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.