Solution (source code)

= Solution

Put $\alpha=\sqrt{m_1}$, $\beta=\sqrt{m_2}$ and $F=\mathbb Q(\alpha)$. The hypotheses make $L/\mathbb Q$ a <biquadratic extension>. To check the <degree of a field extension> is four, if $\beta=x+y\alpha$ with rational $x,y$, squaring gives $xy=0$. The case $y=0$ would make $m_2$ a rational square; the case $x=0$ would make $m_2/m_1$ a rational square. Neither can occur for the specified distinct coprime <square-free integers>. Hence $[L:F]=2$.

The nonidentity <field automorphism> of $L/F$ fixes $\alpha$ and sends $\beta$ to $-\beta$. Thus, for $\gamma=(r+s\alpha)+(t+u\alpha)\beta$, the <field norm> and <field trace> are
$$
\boxed{N_{L/F}(\gamma)=(r+s\alpha)^2-m_2(t+u\alpha)^2,\qquad
\operatorname{Tr}_{L/F}(\gamma)=2(r+s\alpha)}.
$$
If $\gamma$ is an <algebraic integer>, so is its conjugate, and their sum and product are <algebraic integers>. Conversely, put $T=\operatorname{Tr}_{L/F}(\gamma)$ and $N=N_{L/F}(\gamma)$. The identity
$$
\gamma^2-T\gamma+N=0
$$
shows that $\gamma$ is integral over $\mathbb Z[T,N]$. If $T,N$ are <algebraic integers>, the <ring generated by algebraic integers> $\mathbb Z[T,N]$ is integral over $\mathbb Z$. Since <integral dependence is transitive>, $\gamma$ is an <algebraic integer>. This proves the <trace and norm integrality criterion for a quadratic extension>, including elements already in $F$.