Should a metric always map into $\mathbf{R}$?

Typically you see the definition of a metric as a function which maps $X\times X\to\mathbf{R},$ but does this always have to be the case?

Motivating example: When you complete $\mathbf{Q}$ with the Archimedean metric you think of it as mapping into $\mathbf{R},$ but if you were to choose the $p$-adic metric instead it can only take values in $\{0\}\cup p^\mathbf{Z}$. These are elements of $\mathbf{Q}_p$ as well as $\mathbf{R}.$ The difference is then that either your metric maps into an ordered field or one where you can't define any ordering (but you still know that the distances can have different values).

Does not mapping a metric into $\mathbf{R}$ always lead to problems? And are the issues of the example above avoidable?

• I had a similar musing, which led me to ask this question. The answer, as far as my current undertanding goes, is that every Archimedean ordered field embeds into $\mathbb R$ anyway (and you need order for most of the things you usually want to do with a metric), so from the pure abstract view of a metric space we can assume without loss of generality that the codomain of the metric is $\mathbb R$. – Henning Makholm Apr 28 '16 at 9:25
• What Henning Makholm said is how I understand it. In some sense the situation where you are "still constructing $\mathbb{R}$" by the Cauchy completion construction is the only meaningful example. After that you still might have a metric which is only, say, $\mathbb{Q}$-valued, but its range can be embedded into $\mathbb{R}$ anyway, so what do you care? – Ian Apr 28 '16 at 12:05
• This reinforces a point I saw in another question on MSE: if your goal is to understand analysis, you should learn whatever construction of the reals makes sense to you and then start studying analysis. Spending a bunch of time on constructions is surprisingly unhelpful. – Ian Apr 28 '16 at 12:07

It depends on what you want for your "metric". It makes perfect sense as far as the definition goes to replace $\mathbb{R}$ by any totally ordered abelian group. But of course the properties won't be the same...
First note that when you suggest to interpret $|x|_p = p^{-v_p(x)}$ as an element of $\mathbb{Q}_p$, this has the pretty annoying inconvenient that if $x_n\to 0$ in $\mathbb{Q}_p$ then $|x|_p\to \infty$, so this interpretation does not give the $p$-adic topology.
Then let's assume that you define a metric as a map $X\times X \to \Gamma$ where $\Gamma$ is a totally ordered abelian group, with the usual axioms for metrics. This does give you a topology on $X$ by defining open balls as usual, and taking them as a basis for the topology.
But in general this topology need not be secound countable : this strongly uses the fact that in $\mathbb{R}$ there is a sequence $(\varepsilon_n)$ such that $\varepsilon_n>0$ and every $x>0$ satisfies $x<\varepsilon_n$ for some $n$ (take $\varepsilon_n = \frac{1}{n}$). So if you want to keep this very crucial property of metric spaces, you need to assume that such a sequence $\varepsilon_n$ exists in $\Gamma$.
More importantly, if you want that $X$ is the union of the open balls $B(a,n)$ with $n\in \mathbb{N}$ for any $a\in X$, then you need that $\Gamma$ is archimedian (ie for any $\varepsilon>0$ and any $x\in \Gamma$ there in $n\in \mathbb{N}$ such that $n\varepsilon>x$). But that actually implies that $\Gamma$ can be embedded in $\mathbb{R}$ as an ordered group. So if you want that property for metric spaces, then you may assume $\Gamma = \mathbb{R}$ without loss of generality.