Notation
Replace '#' by '!' in the formulas and 'f' by 'factorial' in the Maple call proc(f,n) if you want to compute primes related to the factorial function, or replace '#' by '$' (TeXnicans use \wr) in the formulas and 'f' by 'swing' in the Maple call if you want to refer to the swinging factorial function. Here 'swing' is the function in the box at the right hand side (see A056040). A Maple worksheet is here. Swinging factorials and swinging primes have been studied in: Peter Luschny, Divide, swing and conquer the factorial and the lcm{1,2,...,n}, preprint, April 2008. swing := proc(n)
option remember;
if n = 0 then 1 elif
irem(n, 2) = 1 then
swing(n-1)*n else
4*swing(n-1)/n fi end:
Swinging Primes
Factorial primes, primes which are within 1 of a factorial number.
Swinging primes, primes which are within 1 of a swinging factorial number.
 !  A088054  $  A163074 A74 := proc(f,n)
select(isprime,
map(x -> f(x)+1,[$1..n]));
select(isprime,
map(x -> f(x)-1,[$1..n]));
sort(convert(convert(%%,set) union
convert(%,set),list)) end:
2, 3, 5, 7, 23, 719, 5039, 39916801,
479001599, 87178291199
2, 3, 5, 7, 19, 29, 31, 71, 139, 251, 631, 3433, 12011, 48619, 51479, 51481, 2704157
Primes of the form n# + 1
 !  A088332  $  A163075 A75 := proc(f,n)
select(isprime,
map(x -> f(x)+1,[$1..n]))
end:
2, 3, 7, 39916801, 10888869450418352160768000001 2, 3, 7, 31, 71, 631, 3433, 51481, 2704157
Primes of the form n# - 1.
 !  A055490  $  A163076 A76 := proc(f,n)
select(isprime,
map(x -> f(x)-1,[$1..n]));
sort(%) end:
5, 23, 719, 5039, 479001599, 87178291199 5, 19, 29, 139, 251, 12011, 48619, 51479, 155117519
Numbers n such that n# + 1 is prime.
 !  A002981  $  A163077 A77 := proc(f,n)
select(x -> isprime(f(x)+1),[$0..n])
end:
0, 1, 2, 3, 11, 27, 37, 41, 73, 77, 116, 154, 320 0, 1, 2, 3, 4, 5, 8, 9, 14, 15, 24, 27, 31, 38, 44
Numbers n such that n# - 1 is prime.
 !  A002982  $  A163078 A78 := proc(f,n)
select(x -> isprime(f(x)-1),[$0..n])
end:
3, 4, 6, 7, 12, 14, 30, 32, 33, 38, 94, 166, 324 3, 4, 5, 6, 7, 10, 13, 15, 18, 30, 35, 39, 41, 47
Primes p such that p# + 1 is also prime.
 !  A093804  $  A163079 A79 := proc(f,n)
select(isprime,
select(k -> isprime(f(k)+1),[$0..n]))
end:
2, 3, 11, 37, 41, 73, 26951 2, 3, 5, 31, 67, 139, 631
Primes p such that p# - 1 is also prime.
 !  A103317  $  A163080 A80 := proc(f,n)
select(isprime,
select(k -> isprime(f(k)-1),[$0..n]))
end:
3, 7, 379, 6917 3, 5, 7, 13, 41, 47, 83, 137, 151, 229, 317, 389, 1063
Primes of the form p# + 1 where p is prime.
 !  A103319  $  A163081 A81 := proc(f,n)
select(isprime,[$2..n]);
select(isprime,
map(x -> f(x)+1,%)) end:
3, 7, 39916801 3, 7, 31, 4808643121, 483701705079089804581
Primes of the form p# - 1 where p is prime.
 ! A000000  $  A163082 A82 := proc(f,n)
select(isprime,[$2..n]);
select(isprime,
map(x -> f(x)-1,%)) end:
5, 5039 5, 29, 139, 12011, 5651707681619, 386971244197199
Primes of the form p# + 1 which are the greater of twin primes.
 !  A000000  $  A163083 A83 := proc(f,n)
select(s->isprime(s)
and isprime(s-2),
map(k->f(k)+1,[$4..n])) end;
7  7, 31, 51481, 1580132580471901
Al-Haytham Primes
Al-Haytham is the first person that we know to state:  If p is prime then (p−1)! + 1 is divisible by p. Origin unknown to the author: If p is prime then (p−1)$ − (−1)^floor(p/2) is divisible by p.
Wilson quotients: ((p − 1)# + r(p)) / p, p prime
 !  A007619  $  A163210 WQ := proc(f,r,n)
map(p->(f(p-1)+r(p))/p,
select(isprime,[$1..n])) end:
WQ(factorial,p->1,30);
WQ(swing,p->(-1)^iquo(p+2,2),30);
1, 1, 5, 103, 329891, 36846277, 1230752346353 1,1,1,3,23,71,757,2559,30671,1383331,
5003791
Wilson quotients which are prime
 !  A163212  $  A163211 WQP := proc(f,r,n)
select(isprime,WQ(f,r,n)) end:
WQP(factorial,p->1, 30);
WQP(swing,p->(-1)^iquo(p+2,2), 40);
5, 103, 329891, 10513391193507374500051862069 3, 23, 71, 757, 30671, 1383331, 245273927
Wilson remainders: ((p − 1) # + r(p)) / p mod p, p prime
 !  A002068  $  A163213 WR := proc(f,r,n)
map(p->(f(p-1)+r(p))/p mod p,
select(isprime,[$1..n])) end:
WR(factorial,p->1, 36);
WR(swing,p->(-1)^iquo(p+2,2), 36);
1, 1, 0, 5, 1, 0, 5, 2, 8, 18, 19, 7, 16, 13 1, 1, 1, 3, 1, 6, 9, 13, 12, 2, 19
Wilson primes: (((p − 1)# + r(p)) / p) mod p = 0
 !  A007540  $  A001220 WP := proc(f,r,n)
select(p->(f(p-1)+r(p))/p mod p = 0,
select(isprime,[$1..n])) end:
WP(factorial,p->1, 600);
WP(swing,p->(-1)^iquo(p+2,2), 3600);
5, 13, 563 1093, 3511
Wilson spoilers: composite n which divide (n − 1)# + r(n)
 !  A00000  $  A163209 WS := proc(f,r,n)
select(p->(f(p-1)+r(p))mod p = 0,[$2..n]);
select(q -> not isprime(q),%) end:
WS(factorial,p->1, 600);
WS(swing,p->(-1)^iquo(p+2,2), 6000);
 There are none, as proved by Lagrange. 5907, 1194649, 12327121