I was thinking about Euclid's proof of the infinitude of primes the other day and started thinking about what would happen for different initial sets of primes than the usual first $N$ primes. Is there a finite subset of the primes which never actually hits a composite number when generating numbers as in Euclid's proof?
Consider the following algorithm:
Take a set $A_{k}=\left\{q_{1},\ldots,q_{k}\right\}$ of primes and let $n = q_{1}\cdots q_{k}+1$. If $n$ is prime, start over with $A_{k+1} = A_{k}\cup\left\{n\right\}$. If $n$ is composite, terminate.
Written in a C-like pseudocode:
function euclid(array primes[])
{
n = 1;
steps = 1;
for(i = 0; i < primes.size(); i++)
{
n *= primes[i];
}
n++;
while(isPrime(n))
{
steps++;
primes.append(n);
n = n*(n-1) + 1;
}
return steps;
}
My question is: Does this always terminate for any initial set of primes? If so, how can we express the number of steps in terms of the initial set of primes? Is the number of steps taken unbounded if we vary the initial set of primes?
The only thing I've been able to determine on my own, so far, is that this obviously terminates after the first step whenever 2 isn't included.
Here are some examples (all include 2):
$\{2\}\to\{2,3\}\to\{2,3,7\}\to\{2,3,7,43\}\to\{2,3,7,43,1807\}\to$ Terminate: $13\mid1807$. 4 steps.
$\{2,5\}\to\{2,5,11\}\to\{2,5,11,111\}\to$ Terminate: $3\mid111$. 2 steps.
$\{2,7\}\to\{2,7,15\}\to$ Terminate: $3\mid15$. 1 step.
$\{2,3,5\}\to\{2,3,5,31\}\to\{2,3,5,31,931\}\to$ Terminate: $7\mid931$. 2 steps.
Since $q_{\ell+1} = q_{\ell}\left(q_{\ell}-1\right)+1$ for all $\ell>k$, it seems that looking at the polynomial $x^{2}-x+1$ may provide some insight.
If anyone can link to references for this or similar problems, I'd really appreciate it.