Ask Your Question

Why does the code not work?

asked 2020-06-08 17:24:53 +0200

Moondoggy gravatar image

I want to write a program which gives me all prime ideals in the ring of integers $\mathcal{O}_K $, $K= \mathbb{Q}(\sqrt{-5})$ . They should have the property to be principal. My problem is that the condition if(J.gens()[0]-1 in L): does not really work. By this I want that the generator of the principal ideal minus 1 is contained in the ideal L.

   sage: K.<a> = QuadraticField(-5)
             cl = K.class_group()
              g = cl.gens()[0]
    sage: for norm, ideals in K.ideals_of_bdd_norm(10).items():
             for J in ideals:
                 if (J.is_prime()):
                   if  (cl(J)==g^4):
                     if(J.gens()[0]-1 in L):
                         print norm,J
edit retag flag offensive close merge delete


Have you look at what J.gens() looks like for the various ideals J you are considering?

nbruin gravatar imagenbruin ( 2020-06-08 18:24:46 +0200 )edit

If i leave out the condtion if(J.gens()[0]-1 in L):, then it prints this: 5 Fractional ideal (-a). Now -a is the generator of the principal ideal (-a). If I take again the condition if(J.gens()[0]-1 in L), then this means whether -a-1 is in L and it is but sage does not print me out J.

Moondoggy gravatar imageMoondoggy ( 2020-06-08 18:38:08 +0200 )edit

That -a-1 lies in L should hold, and sage does seem to agree with that. However, J.gens()[0]-1 apparently doesn't, so you should probably print J.gens()[0], or more generally J.gens(), to see why that is the case. That's either going to give you a good, reportable, bug or it shows you what's going wrong.

nbruin gravatar imagenbruin ( 2020-06-09 01:03:38 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-06-09 01:18:36 +0200

rburing gravatar image

What you are looking for is J.gens_reduced() instead of J.gens().

Instead of g^4 you can just write The class group has order $2$ so g^2 is already Instead of comparing classes you can also just ask J.is_principal().

edit flag offensive delete link more


What is the difference between J.gens_reduced() and J.gens()?

Moondoggy gravatar imageMoondoggy ( 2020-06-09 10:40:28 +0200 )edit

See the documentation of gens_reduced: "Express this ideal in terms of at most two generators, and one if possible". By contrast, gens() are just the generators which were given when the ideal was constructed (in this case, by Sage).

rburing gravatar imagerburing ( 2020-06-09 10:48:07 +0200 )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


Asked: 2020-06-08 17:24:53 +0200

Seen: 98 times

Last updated: Jun 09 '20