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, 18 Jun 2023 09:35:56 +0200Python class for the ring $\mathbb{Z}[\sqrt{d}]$ ?https://ask.sagemath.org/question/69249/python-class-for-the-ring-mathbbzsqrtd/How to define and use the ring $\mathbb{Z}[\sqrt{d}]$ in Python?
Is there a class for it? The purpose is to use Sage to verify some long calculations in an ideal generated by two elements. I don't know the name of the ring so it is difficult to declare proper tags.Sat, 17 Jun 2023 12:04:25 +0200https://ask.sagemath.org/question/69249/python-class-for-the-ring-mathbbzsqrtd/Answer by rburing for <p>How to define and use the ring $\mathbb{Z}[\sqrt{d}]$ in Python?
Is there a class for it? The purpose is to use Sage to verify some long calculations in an ideal generated by two elements. I don't know the name of the ring so it is difficult to declare proper tags.</p>
https://ask.sagemath.org/question/69249/python-class-for-the-ring-mathbbzsqrtd/?answer=69264#post-id-69264This is an order in the number field $\mathbb{Q}(\sqrt{d})$:
sage: d = 5
sage: K.<a> = QuadraticField(d)
sage: R = K.order(a)
sage: R.basis()
[1, a]
sage: OK = K.ring_of_integers()
sage: OK.basis()
[1/2*a + 1/2, a]
sage: R.index_in(OK)
2
Other options:
sage: d = 5
sage: ZZ[sqrt(d)]
Order in Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?
sage: d = 5
sage: ZZ[AA(d).sqrt()]
Order in Number Field in a with defining polynomial x^2 - 5 with a = 2.236067977499790?
sage: d = 5
sage: K = QuadraticField(d)
sage: K
Number Field in a with defining polynomial x^2 - 5 with a = 2.236067977499790?
sage: ZZ[K.gen()]
Order in Number Field in a0 with defining polynomial x^2 - 5 with a0 = 2.236067977499790?Sun, 18 Jun 2023 09:35:56 +0200https://ask.sagemath.org/question/69249/python-class-for-the-ring-mathbbzsqrtd/?answer=69264#post-id-69264