Wilson's Theorem

Author

Eric W. Weisstein
January 10, 2009

This notebook downloaded from http://mathworld.wolfram.com/notebooks/NumberTheory/WilsonsTheorem.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/WilsonsTheorem.html.

©2009 Wolfram Research, Inc. except for portions noted otherwise

Check

primes=Prime[Range[10^4]];//Timing
composites=Complement[Range[5,Last[#]],#]&[primes];//Timing

Mod[(#-1)!,#,-#/2]&/@primes//Union//Timing

Mod[(#-1)!,#,-#/2]&/@composites//Union//Timing

Corollary to Wilson's Theorem

Primes of the form 4 k+1, i.e., ≡ 1 (mod 4).

list1=Select[Table[Prime[n],{n,200}],Mod[#,4]==1&]

Values of x such that (((2 x)!)^2)≡-1 ≡ 4x (mod 4x+1)

x=Select[Range[200],Mod[(2#)!^2,4#+1]==4#&]

Primes of the form p=4 x+1 corresponding to values of x above

list2=4#+1&/@x

Comparing lists shows they are identical

n=Min@@Length/@{list1,list2};
Complement[Take[list1,n],Take[list2,n]]

Gauss's Generalization

P[n_]:=Times@@Select[Range[n],GCD[#,n]==1&]

P/@Range[20]

Mod[P[1],1]

Mod[1,1]

Mod[P[#],#,-#/2]&/@Range[100]

<<NumberTheory`NumberTheoryFunctions`

GaussQ[1]:=0
GaussQ[2]:=-1
GaussQ[4]:=-1
GaussQ[n_]:=If[(PrimePowerQ[n]||PrimePowerQ[n/2])&&!IntegerQ[Log[2,n]],-1,1]

GaussQ/@Range[33]

l2=GaussQ/@Range[33]

Equal@@@Table[GaussQ[n]==Mod[P[n],n,-n/2],{n,2,1000}]//Union//Timing

Sándór's Extension

Sum[i,{i,k}]

Product[%,{k,n}]

2FullSimplify[%]

FullSimplify[%,n∈Integers&&n>0]

FunctionExpand[%,n∈Integers&&n>0]

Table[Mod[(2^(1-n)) n! (n+1)!,2n+1,-(2n+1)/2],{n,0,20}]

Table[If[PrimeQ[2n+1],
Mod[(-1)^Binomial[n+2,2],2n+1,-(2n+1)/2],
0],{n,0,20}]