Example of incomplete metric on $\mathbb{R}$? I was wondering if the following is a valid example of an incomplete metric on $\mathbb{R}$. Let $d(x,y)$ be defined as follows: if $x,y\in\mathbb{Q}$ then $d(x,y) = |x-y|$; if $x,y\in\mathbb{R}\setminus\mathbb{Q}$ then $d(x,y) = |x-y|$; otherwise (if one is rational and the other is not), let $d(x,y) = |x-y|+1$.
We verify this is a metric. The only concern is triangle inequality. Let $x,y,z\in\mathbb{R}$, if $x,z\in\mathbb{Q}$ or $x,z\in\mathbb{R}\setminus\mathbb{Q}$, then we have
$$d(x,z)\leq d(x,y) + d(y,z)$$
regardless of if $y\in\mathbb{Q}$ or $y\in\mathbb{R}\setminus \mathbb{Q}$ since either case can only increase the RHS. On the other hand, if $x\in\mathbb{Q}$ and $z\in\mathbb{R}\setminus \mathbb{Q}$, then the LHS gets 1 added to it but the RHS does as well, so the triangle inequality holds.
For incompleteness, consider a sequence of rationals converging to $\pi$ in the Euclidean norm. Since the metric restricted to rationals is simply the Euclidean metric, this is a Cauchy sequence. However, for each $x_n$ in the sequence is rational, it cannot converge to an irrational number as $d(x_n,y)\geq 1$ for all $y\in\mathbb{R}\setminus \mathbb{Q}$. On the other hand, $x_n$ cannot converge to a rational as well: if it does, then it must converge to that rational (say $q$) in the Euclidean norm, which is a contradiction since it cannot converge to both $\pi$ and $q$ in the Euclidean norm.
 A: I dare say your example works and is correct. It's the sum of $\Bbb Q$ and $\Bbb R \setminus \Bbb Q$ topologically.
An easier and more standard example is to define e.g. $d(x,y)=|\frac{x}{|x|+1}-\frac{y}{1+|y|}|$ for which being a metric is easier to show, as it is of the form $|f(x)-f(y)|$ already and needs no cases. $x_n = n$ is then Cauchy and without limit. The same holds for $x_n = -n$. This metric induces the standard topology on $\Bbb R$.
A: $\mathbb{R}$ is considered with the standard topology, so you want a metric that induces this topology and is not complete.
The standard idea is to exhibit a metric space homeomorphic to $\mathbb{R}$, but whose metric is not complete. Any open interval of $\mathbb{R}$ that is not $\mathbb{R}$ works. Now use the homeomorphism to get a metric on $\mathbb{R}$.
Examples:

*

*$\mathbb{R} \to (0, \infty)$, $x \mapsto \exp x$. The induced metric on $\mathbb{R}$ is $d_1(x,y) = \lvert\exp x - \exp y\rvert$


*$\mathbb{R} \to (-1,1)$, $x \mapsto \frac{x}{\sqrt{1+x^2}}$ (with inverse $t \mapsto \frac{t}{\sqrt{1-t^2}}$). The induced metric is $d_2(x,y) = |\frac{x}{\sqrt{1+x^2}} - \frac{y}{\sqrt{1+y^2}}|$
Note: It appears elsewhere on this site the result: $X$ non-compact metric space implies there exists a metric on $X$ that is not complete.
