Ring of integers of a quadratic field (source code)

= Ring of integers of a quadratic field
{title2=$\mathcal O_{\mathbb Q(\sqrt d)}=\mathbb Z[\omega_d]$}

Let $d\ne0,1$ be a <square-free integer>, and let $K=\mathbb Q(\sqrt d)$ be the associated <quadratic field>. Then
$$
\mathcal O_K=\mathbb Z[\omega_d],\qquad
\omega_d=\begin{cases}(1+\sqrt d)/2,&d\equiv1\pmod4,\\\sqrt d,&d\equiv2,3\pmod4.\end{cases}
$$
The pair $1,\omega_d$ is an <integral basis>. The <field discriminant> is $d$ in the first case and $4d$ in the second. This statement requires $d$ to be a <square-free integer>: for example, $\mathbb Q(\sqrt8)=\mathbb Q(\sqrt2)$ but $\mathbb Z[\sqrt8]$ omits $\sqrt2$.https://kconrad.math.uconn.edu/blurbs/gradnumthy/quadraticgrad.pdf[Conrad, Factoring in Quadratic Fields, Theorem 3.4]{ref}

For $d=2$, the <integral basis> is $1,\sqrt2$, and the <field discriminant> is $8$. For $d=5$, it is $1,\phi$ with $\phi=(1+\sqrt5)/2$, and the <field discriminant> is $5$. The identity $\phi^2=\phi+1$ makes $\mathbb Z[\phi]$ closed under multiplication. Since $\sqrt5=2\phi-1$, the smaller <order in a number field> $\mathbb Z[\sqrt5]$ consists precisely of $a+b\phi$ with even $b$. This computes its index two and shows concretely why adjoining a square root does not always supply every <algebraic integer>.

In this second <integral basis>, the <field norm> is
$$
N_{\mathbb Q(\sqrt5)/\mathbb Q}(a+b\phi)=a^2+ab-b^2.
$$
In particular, $N(\phi)=-1$ and $\phi^{-1}=\phi-1$: the extra <algebraic integer> is also a <unit>. The <units of the quadratic field Q square root of five> describe all its powers.