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.Sun, 16 May 2021 15:25:08 +0200How do I write a code which gives me all prime ideals up to a specific norm?https://ask.sagemath.org/question/51803/how-do-i-write-a-code-which-gives-me-all-prime-ideals-up-to-a-specific-norm/
I am new to sage. This program should give me all prime ideals in $\mathcal{O}_K$ with $K=\mathbb{Q}(i)$ up to norm $5$. So far I have
:
sage: K.<a> = QuadraticField(-1)
for j in range(5):
L= K.ideals_of_bdd_norm(j)
if L.is_prime():
print L
Sun, 07 Jun 2020 13:50:15 +0200https://ask.sagemath.org/question/51803/how-do-i-write-a-code-which-gives-me-all-prime-ideals-up-to-a-specific-norm/Comment by slelievre for <p>I am new to sage. This program should give me all prime ideals in $\mathcal{O}_K$ with $K=\mathbb{Q}(i)$ up to norm $5$. So far I have
:</p>
<pre><code>sage: K.<a> = QuadraticField(-1)
for j in range(5):
L= K.ideals_of_bdd_norm(j)
if L.is_prime():
print L
</code></pre>
https://ask.sagemath.org/question/51803/how-do-i-write-a-code-which-gives-me-all-prime-ideals-up-to-a-specific-norm/?comment=57137#post-id-57137Related:
- [Math Stack Exchange question 3709597: List prime ideals with norm up to 3 in a quadratic number field](https://math.stackexchange.com/questions/3709597)
- [Ask Sage question 43698: Enumerating prime ideals in Sage](https://ask.sagemath.org/question/43698)Sun, 16 May 2021 15:25:08 +0200https://ask.sagemath.org/question/51803/how-do-i-write-a-code-which-gives-me-all-prime-ideals-up-to-a-specific-norm/?comment=57137#post-id-57137Answer by tmonteil for <p>I am new to sage. This program should give me all prime ideals in $\mathcal{O}_K$ with $K=\mathbb{Q}(i)$ up to norm $5$. So far I have
:</p>
<pre><code>sage: K.<a> = QuadraticField(-1)
for j in range(5):
L= K.ideals_of_bdd_norm(j)
if L.is_prime():
print L
</code></pre>
https://ask.sagemath.org/question/51803/how-do-i-write-a-code-which-gives-me-all-prime-ideals-up-to-a-specific-norm/?answer=51826#post-id-51826You just have to do:
sage: K.ideals_of_bdd_norm(5)
{1: [Fractional ideal (1)],
2: [Fractional ideal (a + 1)],
3: [],
4: [Fractional ideal (2)],
5: [Fractional ideal (2*a + 1), Fractional ideal (-a - 2)]}
What you get is a Python dictionary, whose keys are the norms, and the values are Python lists of the ideals with given norm.
For example:
sage: K.ideals_of_bdd_norm(5)[3]
[]
is an empty list since there is no ideal with norm 3
sage: K.ideals_of_bdd_norm(5)[5]
[Fractional ideal (2*a + 1), Fractional ideal (-a - 2)]
is a list with 2 elements: you can access them as follows:
sage: K.ideals_of_bdd_norm(5)[5][0]
Fractional ideal (2*a + 1)
sage: K.ideals_of_bdd_norm(5)[5][1]
Fractional ideal (-a - 2)
Now, if you want all those ideals without caring about their norm, you can do:
sage: d = K.ideals_of_bdd_norm(5)
sage: [f for i in d for f in d[i]]
[Fractional ideal (1),
Fractional ideal (a + 1),
Fractional ideal (2),
Fractional ideal (2*a + 1),
Fractional ideal (-a - 2)]
or
sage: flatten(d.values())
[Fractional ideal (1),
Fractional ideal (a + 1),
Fractional ideal (2),
Fractional ideal (2*a + 1),
Fractional ideal (-a - 2)]
Mon, 08 Jun 2020 12:47:12 +0200https://ask.sagemath.org/question/51803/how-do-i-write-a-code-which-gives-me-all-prime-ideals-up-to-a-specific-norm/?answer=51826#post-id-51826