Ask Your Question
1

list of all prime powers -1

asked 2021-04-10 03:40:02 +0100

GA3165 gravatar image

updated 2021-04-10 03:53:12 +0100

The primes () method gives the list of all primes. Similarly, I need a list (Say PP) that consists of all $p^k-1$ where $p$ is a prime and $k \ge 1$. How to create this infinite list?

Also, I want all possible finite products of elements of PP. Using this I want to understand when two such products are equal.

How to do this? Kindly share your thoughts. Thank you.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-04-10 05:34:12 +0100

Max Alekseyev gravatar image

Primes() is not a list, but essentially a generator of primes with some additional functions. While it can generate primes one by one, it does not store them all at once anywhere (and so it's not a list). We can create a generator for integers of the form $p^k - 1$ in their natural order like

PP = (q-1 for q in NN if is_prime_power(q))

As for finite products of elements of PP, again we cannot store them in the list unless they are somehow bounded. So, you need to be a bit more specific how you want to generate those products.

edit flag offensive delete link more

Comments

PP = (q-1 for q in NN if is_prime_power(q))

This generator will return the list pf prime any power - 1, without regard to k...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-04-10 19:07:10 +0100 )edit

This is what OP asked.

Max Alekseyev gravatar imageMax Alekseyev ( 2021-04-11 01:11:43 +0100 )edit

This is what OP asked.

I didn't read it as such ; but you may be right. In which case your brute-force solution is better than what I proposed.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-04-11 03:00:59 +0100 )edit

@Max Alekseyev Thank you. How to list the elements less than 100 from PP?

GA3165 gravatar imageGA3165 ( 2021-04-12 06:27:50 +0100 )edit

For example:

for q in PP:
  if q>=100:
    break
  print(q)
Max Alekseyev gravatar imageMax Alekseyev ( 2021-04-12 06:42:25 +0100 )edit
0

answered 2021-04-10 19:04:44 +0100

Emmanuel Charpentier gravatar image

One possible realization as a generator :

def PGm1(k):
    """
    Returns a generator for the sequence p(i)^k-1  in i
    where p(i) is the i-th prime.

    Example : the n first terms of the sequence can be obtained by :

        Gk = PGm1(k)
        list(Gk.__next__() for u in range(n))
    """
    r = 0
    while True:
        r = r.next_prime()
        yield r^k - 1

Example of use :

sage: G2=PGm1(2)
sage: list(G2.__next__() for u in range(5))
[3, 8, 24, 48, 120]

Beware : this generator is infinite. Using it "raw" won't return...

edit flag offensive delete link more

Comments

Thank you. But I want for arbitrary k :)

GA3165 gravatar imageGA3165 ( 2021-04-12 06:25:44 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-04-10 03:40:02 +0100

Seen: 718 times

Last updated: Apr 10 '21