# 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

edit retag close merge delete

( 2021-05-16 15:25:08 +0200 )edit

Sort by ยป oldest newest most voted

You 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)]

more