%mathpiper,def="IsIrregularPrime"

5  # IsIrregularPrime(p_IsComposite)	<-- False;
// First irregular prime is 37
5  # IsIrregularPrime(_p)_(p<37)	<-- False;

// an odd prime p is irregular iff p divides the numerator of a Bernoulli number B(2*n) with
// 2*n+1<p
10 # IsIrregularPrime(p_IsPositiveInteger) <--
[
	Local(i,irregular);

	i:=1;
	irregular:=False;

	While( 2*i + 1 < p And (irregular = False) )[
		If( Abs(Numerator(Bernoulli(2*i))) % p = 0, irregular:=True );
		i++;
	];
	irregular;

];

%/mathpiper



%mathpiper_docs,name="IsIrregularPrime",categories="User Functions;Number Theory;Predicates"
*CMD IsIrregularPrime --- test for an irregular prime
*STD
*CALL
	IsIrregularPrime(n)

*PARMS

{n} -- positive integer

*DESC

This function returns {True} if {n} is an irregular prime. A prime number $n$
is irregular if and only if {n} divides the numerator of a Bernoulli number $B[2*i]$,
where $2*i+1 < n $. Small irregular primes are quite rare; the only irregular primes under 100
are  37, 59 and 67. Asymptotically, roughly 40{%} of primes are irregular.

*E.G.

In> IsIrregularPrime(5)
Result: False;
In> Select(1 .. 100, IsIrregularPrime)
Result: {37,59,67};

*SEE IsPrime
%/mathpiper_docs