I am new to sage and I searched the documentation, but could not find an answer for defining the ring of integers.

n = 7777
d = next_prime(n)
K.<a> = NumberField(x^2-d)

Now I want to define the ring of integers of the numberfield $K$. Is there a command which defines the ring of integers? Any suggestions how to do this?


1 Answer 1


As one might guess, the ring of integers of K can be obtained as K.ring_of_integers().

One way to discover this is to type K.rin and then the TAB key to see what methods K has that start by rin. You will see the auto-completion to K.ring_of_integers.

sage: n = 7777
sage: d = next_prime(n)
sage: K.<a> = NumberField(x^2-d)
sage: O = K.ring_of_integers()
sage: O
Maximal Order in Number Field in a with defining polynomial x^2 - 7789
  • $\begingroup$ Haha, thank you. I am coding in cocalc, so there is somehow no function with the TAB key. It is sad, that one does not find this command by searching in the documentation and google about "ring of integeres". Even the assistant within cocalc does not show it. If you want you can recommend other sources. Anyways, thank you for your help! $\endgroup$
    – user408858
    Commented Apr 28, 2018 at 23:01
  • $\begingroup$ When working in CoCalc, (a) if you are working in the Sage REPL in a CoCalc terminal, it works fine; (b) if you are working in a Jupyter worksheet (blah.ipynb) running the SageMath kernel, or in a CoCalc worksheet (blah.sagews), it works fine too, but you would need to first evaluate the first three lines, so that K is defined, and then you can inspect the methods of K by tab-completion. So, after the first three lines, hit shift-return, then when you are typing the next line, you can tab-complete from O = K.rin. $\endgroup$ Commented Apr 28, 2018 at 23:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .