1

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?

Piotr Semenov
  • 1,761
  • 16
  • 24

1 Answers1

2

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.

Piotr Semenov
  • 1,761
  • 16
  • 24
  • 2
    It seems to be already known in the OEIS : https://oeis.org/search?q=0%2C1%2C2%2C0%2C3%2C0%2C1%2C0%2C0%2C0&language=english&go=Search – Sylvain JULIEN Sep 17 '17 at 20:37