Solution (source code)

= Solution

Again put $\alpha=\sqrt{m_1}$ and $\beta=\sqrt{m_2}$. The <ring of integers> of each of the three quadratic subfields has <integral basis> $1,\alpha$, $1,\beta$, or $1,\alpha\beta$, respectively: their square-free radicands are respectively congruent to $3,2,2$ modulo four. The <field traces> of the <algebraic integer> $\gamma$ to those subfields are
$$
a+b\alpha,\qquad a+c\beta,\qquad a+d\alpha\beta,
\qquad a=2r,\ b=2s,\ c=2t,\ d=2u.
$$
They are <algebraic integers>, so comparison with each <integral basis> gives
$$
\boxed{a,b,c,d\in\mathbb Z}.
$$
This use of all three subfields is needed to control $d$ as well as the other coefficients.

The <field norm> to $\mathbb Q(\alpha)$ is
$$
N_{L/\mathbb Q(\alpha)}(\gamma)
=\frac{a^2+m_1b^2-m_2c^2-m_1m_2d^2}{4}
+\frac{ab-m_2cd}{2}\alpha.
$$
Its two coefficients must be <integers>. The second condition says $ab$ is even, since $m_2$ is even. Reducing the numerator of the first coefficient modulo four gives
$$
a^2-b^2-2(c^2+d^2)\equiv0\pmod4.
$$
Reduction modulo two first gives $a\equiv b\pmod2$. Since $ab$ is even, both $a$ and $b$ are even. The same congruence now gives $c^2+d^2\equiv0\pmod2$, or $c\equiv d\pmod2$. Therefore every <algebraic integer> has the form
$$
\gamma=\frac a2+\frac b2\alpha+\frac{c-d}{2}\beta+d w,
\qquad w=\frac{\beta+\alpha\beta}{2},
$$
with four <integer> coefficients.

For the converse, $1,\alpha,\beta$ are <algebraic integers>, and
$$
w^2=\frac{m_2(1+m_1)}4+\frac{m_2}2\alpha\in\mathbb Z[\alpha].
$$
Here $4\mid1+m_1$ and $2\mid m_2$, so both coefficients are <integers>. The <monic polynomial> $X^2-w^2$ and <integral dependence is transitive> show that $w$ is an <algebraic integer>. The four displayed generators are rationally <linearly independent>, since their coefficient <matrix> in $1,\alpha,\beta,\alpha\beta$ has <determinant> $1/2$. Hence the <integral basis for coprime biquadratic radicands congruent to three and two> is
$$
\boxed{\left\{1,\sqrt{m_1},\sqrt{m_2},\frac{\sqrt{m_2}+\sqrt{m_1m_2}}2\right\}}.
$$
In this formula $\sqrt{m_1m_2}$ denotes the product $\alpha\beta$ of the chosen square roots; this convention also handles negative radicands.