How can I define the "primality order" in pari/gp?

80 views Asked by At

I'm deeply interested in number theory and want to test some of my ideas in pari/gp, but am not familiar with this software. Specifically, I want to define a 'primeorder' function that maps an integer n to what I call its primality order, which is 0 if and only if n is composite and equal to the least integer k such that the k-th iterate of the prime counting function evaluated at n is composite otherwise.

How can I define such a function in pari/gp?

1

There are 1 answers

1
Piotr Semenov On BEST ANSWER

Please, review this:

primeorder(x) = {
  if(!isprime(x), return(0));

  my(k=1, p=primepi(x));
  while(isprime(p), p=primepi(p); k++);
  return(k);
}

I highly recommend to read PARI/GP tutorial.