ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 12 Apr 2021 06:42:25 +0200list of all prime powers -1https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/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.Sat, 10 Apr 2021 03:40:02 +0200https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/Answer by Max Alekseyev for <p>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? </p>
<p>Also, I want all possible finite products of elements of PP. Using this I want to understand when two such products are equal.</p>
<p>How to do this? Kindly share your thoughts. Thank you.</p>
https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?answer=56588#post-id-56588`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.Sat, 10 Apr 2021 05:34:12 +0200https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?answer=56588#post-id-56588Comment by Max Alekseyev for <p><code>Primes()</code> 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</p>
<p><code>PP = (q-1 for q in NN if is_prime_power(q))</code></p>
<p>As for finite products of elements of <code>PP</code>, 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.</p>
https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?comment=56625#post-id-56625For example:
for q in PP:
if q>=100:
break
print(q)Mon, 12 Apr 2021 06:42:25 +0200https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?comment=56625#post-id-56625Comment by GA3165 for <p><code>Primes()</code> 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</p>
<p><code>PP = (q-1 for q in NN if is_prime_power(q))</code></p>
<p>As for finite products of elements of <code>PP</code>, 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.</p>
https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?comment=56623#post-id-56623@Max Alekseyev Thank you. How to list the elements less than 100 from PP?Mon, 12 Apr 2021 06:27:50 +0200https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?comment=56623#post-id-56623Comment by Emmanuel Charpentier for <p><code>Primes()</code> 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</p>
<p><code>PP = (q-1 for q in NN if is_prime_power(q))</code></p>
<p>As for finite products of elements of <code>PP</code>, 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.</p>
https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?comment=56609#post-id-56609> 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.Sun, 11 Apr 2021 03:00:59 +0200https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?comment=56609#post-id-56609Comment by Max Alekseyev for <p><code>Primes()</code> 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</p>
<p><code>PP = (q-1 for q in NN if is_prime_power(q))</code></p>
<p>As for finite products of elements of <code>PP</code>, 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.</p>
https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?comment=56607#post-id-56607This is what OP asked.Sun, 11 Apr 2021 01:11:43 +0200https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?comment=56607#post-id-56607Comment by Emmanuel Charpentier for <p><code>Primes()</code> 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</p>
<p><code>PP = (q-1 for q in NN if is_prime_power(q))</code></p>
<p>As for finite products of elements of <code>PP</code>, 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.</p>
https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?comment=56595#post-id-56595> `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`...Sat, 10 Apr 2021 19:07:10 +0200https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?comment=56595#post-id-56595Answer by Emmanuel Charpentier for <p>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? </p>
<p>Also, I want all possible finite products of elements of PP. Using this I want to understand when two such products are equal.</p>
<p>How to do this? Kindly share your thoughts. Thank you.</p>
https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?answer=56594#post-id-56594One 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...Sat, 10 Apr 2021 19:04:44 +0200https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?answer=56594#post-id-56594Comment by GA3165 for <p>One possible realization as a generator :</p>
<pre><code>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
</code></pre>
<p>Example of use :</p>
<pre><code>sage: G2=PGm1(2)
sage: list(G2.__next__() for u in range(5))
[3, 8, 24, 48, 120]
</code></pre>
<p>Beware : this generator is <em>infinite</em>. Using it "raw" won't return...</p>
https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?comment=56622#post-id-56622Thank you. But I want for arbitrary k :)Mon, 12 Apr 2021 06:25:44 +0200https://ask.sagemath.org/question/56587/list-of-all-prime-powers-1/?comment=56622#post-id-56622