Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

list of all prime powers -1

asked 4 years ago

GA3165 gravatar image

updated 4 years ago

The primes () method gives the list of all primes. Similarly, I need a list (Say PP) that consists of all pk1 where p is a prime and k1. 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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 4 years ago

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 pk1 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.

Preview: (hide)
link

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 ( 4 years ago )

This is what OP asked.

Max Alekseyev gravatar imageMax Alekseyev ( 4 years ago )

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 ( 4 years ago )

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

GA3165 gravatar imageGA3165 ( 4 years ago )

For example:

for q in PP:
  if q>=100:
    break
  print(q)
Max Alekseyev gravatar imageMax Alekseyev ( 4 years ago )
0

answered 4 years ago

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...

Preview: (hide)
link

Comments

Thank you. But I want for arbitrary k :)

GA3165 gravatar imageGA3165 ( 4 years ago )

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: 4 years ago

Seen: 846 times

Last updated: Apr 10 '21