Solution (source code)

= Solution

The <idele group> is the multiplicative <restricted product>
$$
J_K=\prod_v'K_v^\times
$$
with respect to $\mathcal O_v^\times$ at the finite <places of a number field>; $K_v$ is the <completion of a valued field> at the place $v$. Thus each tuple has nonzero components, and all but finitely many finite components are <units>. Its <restricted product topology on the idele group> has basic open sets $\prod_{v\in S}W_v\times\prod_{v\notin S}\mathcal O_v^\times$, where $S$ is finite and contains the infinite places, and each $W_v$ is open in $K_v^\times$. In particular $U_K$ is an open subgroup.

Embed $K^\times$ diagonally. Take a neighbourhood of one whose finite components all lie in $\mathcal O_v^\times$ and whose infinite components satisfy $|x_v-1|<1/2$ in the usual real or complex modulus. A diagonal element there is an algebraic <unit> $a$. If $a\ne1$, then $a-1$ is a nonzero <algebraic integer>, so its <field norm> is a nonzero integer. But
$$
0<|N_{K/\mathbb Q}(a-1)|=\prod_{\sigma\text{ real}}|\sigma(a)-1|\prod_{\sigma\text{ complex}}|\sigma(a)-1|^2<1,
$$
a contradiction. Thus \b[$K^\times$ is discrete]. It is also closed: in a topological group, a subgroup with an isolated identity cannot have an external accumulation point, since quotients of two nearby subgroup elements would approach the identity.

Send an <idele> to its associated <fractional ideal> by
$$
I(x)=\prod_{v\text{ finite}}\mathfrak p_v^{\operatorname{ord}_v(x_v)}.
$$
Only finitely many exponents are nonzero. This homomorphism is onto, by choosing powers of local <uniformizers>, and its kernel is $U_K$. Diagonal elements map to <principal fractional ideals>. The resulting quotient gives
$$
\boxed{J_K/(K^\times U_K)\cong\operatorname{Cl}(K).}
$$
It is a topological isomorphism when the <ideal class group> is given the discrete <topology>, since $U_K$ is open.

Use normalized local moduli: real modulus, squared complex modulus, and $|\pi_v|_v=(N\mathfrak p_v)^{-1}$ at a finite place. The <idelic modulus> $\|x\|=\prod_v|x_v|_v$ defines $J_K^1=\ker\|\cdot\|$, the <norm-one idele group>. The <product formula> puts $K^\times$ inside this kernel. Every ideal class has a representative in $J_K^1$, because an infinite component can be rescaled to correct the modulus without altering its <fractional ideal>. The compact space $J_K^1/K^\times$ therefore maps continuously onto the discrete <ideal class group>. Its image must be finite, proving \b[$\operatorname{Cl}(K)$ is finite].

For the <Dirichlet unit theorem>, put $U^1=U_K\cap J_K^1$ and $E=K^\times\cap U^1=\mathcal O_K^\times$. Let $r_1$ count real embeddings and $r_2$ count conjugate complex pairs. Infinite logarithms define a continuous surjection
$$
\ell:U^1\longrightarrow H=\{(t_1,\ldots,t_{r_1+r_2})\in\mathbb R^{r_1+r_2}:\sum_i t_i=0\},
$$
using $\log|x_v|$ at real places and $2\log|x_v|$ at complex places. Its kernel is <compact>: it consists of real signs, complex unit circles, and the product of compact finite-place unit groups. More generally the inverse image of a bounded closed subset of $H$ is <compact>. Since $E$ is closed and discrete, its intersection with each such inverse image is finite. Hence $\Lambda=\ell(E)$ is discrete in $H$, and the kernel $E\cap\ker\ell$ is a finite group. It is exactly the <roots of unity> $\mu(K)$, since every element of a finite multiplicative group has finite order and every <root of unity> has all local moduli one.

The image of $U^1$ in $J_K^1/K^\times$ is an open subgroup, hence also closed, and is homeomorphic to $U^1/E$. The assumed compactness therefore makes $U^1/E$ <compact>, and its continuous quotient $H/\Lambda$ is <compact>. A discrete cocompact subgroup of a real <vector space> is a full <Euclidean lattice>, of rank $\dim H=r_1+r_2-1$. Thus $E/\mu(K)\cong\mathbb Z^{r_1+r_2-1}$, and lifting a lattice basis splits off the free factor:
$$
\boxed{\mathcal O_K^\times\cong\mu(K)\times\mathbb Z^{r_1+r_2-1}.}
$$
This derives both finiteness and the unit rank from the stated compactness assumption, rather than assuming either conclusion to prove compactness.