Bell numbers have been studied by mathematicians since the 19th century, and their roots go back to medieval Japan, but they are named after Eric Temple Bell, who wrote about them in the 1930s.
Some of the Bell numbers are also prime. Gardner raised the question: Are there infinitely many prim numbers?
The largest currently known prime Bell number is B(2841), aproved in year 2006. This means there is a large gap after B(2),B(3),B(7),B(13),B(42), B(55).
Starting with B(0) = B(1) = 1, the first few Bell numbers are:
1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975
package bellnumber;
import java.math.BigInteger;
import static java.math.BigInteger.ONE;
/**
*
* @author Rolf
*/
public class BellNumber {
static BigInteger B[] = new BigInteger[8500]; // up to Bell(4096) ok
static Boolean PrimChk=false;
//--------------------------------------------------------------------------
public static int build(int e) {
// e End Index
// return Bell number Index = next End Index
for (int i = 0; i <= e; i++) {
B[e + i + 1] = B[ i].add(B[e + i]);
}
// move result sequence forward to save B[] Array space
for (int i = 0; i <= e+1; i++) {
B[i]=B[e + i];
}
return ++e;
}
//--------------------------------------------------------------------------
public static void show( int b,int idx ) {
String isPrim="?";
if (PrimChk|| idx<57) // do the prim only for low values
if ( B[idx].isProbablePrime(10000)) isPrim="y"; else isPrim="-";
System.out.println("Bell("+b+") \t=\t"+B[idx].toString().length()+"\t"+isPrim+"\t"+B[idx]);
}
//--------------------------------------------------------------------------
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Start to create Bell numbers");
System.out.println("n\t\t=\tdigits\tisPrim\tBell number");
int max=8;
if (args.length>0)
max= (int) new Integer(args[0]);
if (args.length>1)
PrimChk= args[1].contains("y");
// 0 1 2 3 4 5 6 7 8 9 10 idx
// 1 1 2 3 5 7 10 15 20 27 37 52 B
// ! ! ! ! ! ! Bell
// howto calc Bell(5)=52;idx=10
// prerequiste:
// we know all B, starting
// from Bell(3)=5;Idx=3
// till Bell(4)=15;idx=6
// from startIdx = 3 till stopIdx= 6
// B(n)=B[startIdx]+B[stopIdx]
//
// finaly shift B to start
B[0] = ONE; // init
B[1] = ONE; // init
int b = 0;
// show first 2 Bell numbers
show(0,0);
show(1,1);
for (int i = 1; i < max; i++) {
b = build(b); // new Bell number index b
show(i+1,b); // show i+1 Bell Number
}
}
}