Are all subrings of the rationals Euclidean domains?

This is a purely recreational question — I came up with it when setting an undergraduate example sheet.

Let’s go with Wikipedia’s definition of a Euclidean domain. So an ID $R$ is a Euclidean domain (ED) if there’s some $\phi:R\backslash\{0\}\to\mathbf{Z}_{\geq0}$ or possibly $\mathbf{Z}_{>0}$ (I never know what $\mathbf{N}$ means, and the Wikipedia page (at the time of writing) uses $\mathbf{N}$ as the target of $\phi$, but in this
case it doesn’t matter, because I can just add one to $\phi$ if necessary) such that the usual axioms hold.

Now onto subrings of the rationals. The subrings of the rationals turn out to be in bijection with the subsets of the prime numbers. If $X$ is a set of primes, then define $\mathbf{Z}_X$ to be the rationals $a/b$ with $b$ only divisible by primes in $X$. Different sets $X$ give different subrings, and all subrings are of this form. This needs a little proof, but a little thought, or a little googling, leads you there.

If $X$ is empty, then $\mathbf{Z}_X=\mathbf{Z}$, which is an ED: the usual $\phi$ taken is $\phi(x)=|x|$.

If $X$ is all the primes then $\mathbf{Z}_X=\mathbf{Q}$ and this is an ED too (at least according to Wikipedia — I think some sources demand that an ED is not a field, but let’s not go there); we can just let $\phi$ be constant.

If $X$ is all but one prime, say $p$, then $\mathbf{Z}_X$ is the localisation of $\mathbf{Z}$ at $(p)$, and $\phi$ can be taken to be the $p$-adic valuation (if we’re allowing $\phi$ to take the value zero, which we may as well). Note however that this is a rather different “style” of $\phi$ to the case $X$ empty: this $\phi$ is “non-archimedean” in origin, whereas in the case of $X$ empty we used an “archimedean” $\phi$. This sort of trick generalises to the case where $X$ is all but a finite set of primes — see the “Dedekind domain with only finitely many non-zero primes” example on the Wikipedia page.

Of course the question is: if $X$ is now an arbitrary set of primes, is $\mathbf{Z}_X$ an ED?

Solutions Collecting From Web of "Are all subrings of the rationals Euclidean domains?"

Yes. Let $\phi(a/b) = |a|$ where $a/b$ is written in lowest terms. To see that this is a Euclidean function, let $a/b,c/d\in \mathbb{Z}_X$ be nonzero and in lowest terms and write
$$\frac{a}{b}=\frac{nd}{b}\cdot \frac{c}{d}+\frac{s}{t}$$ which means that $\phi(s/t)=\phi((a-nc)/b)\leq |a-nc|$ which for a suitable value of $n$ is less than $\phi(a/b) = |a|$.