Checking if a given $d(x,y)$ is a metric 
For $x,y$ $\in$ $[0,1]$, let
  $$d(x,y)= \begin{cases}
|x-y|,  & \text{if $x-y \in \mathbb{Q} $} \\[2ex]
2, & \text{if $x-y \notin \mathbb{Q}$}
\end{cases}$$
  where $\mathbb{Q}$ is a set of rational numbers.
  Find if $d$ is a metric in $[0,1]$.

So what I've already done is:
1) $d(x,y)=0$ iff $x=y \Rightarrow$ $d(x,x)=|x-x|=0$ because $x-x=0 \in \mathbb{Q} $
2) $d(x,y)=d(y,x) \Rightarrow$
2.1) if $x-y \in \mathbb{Q} $ and $y-x \in \mathbb{Q}$ then $|x-y|=|y-x|$, 
2.2) if $x-y \notin \mathbb{Q} $ and $y-x \notin \mathbb{Q} $ then $2=2$ - ok
2.3) if $x-y \in \mathbb{Q} $ and $y-x \notin \mathbb{Q} $ then $|x-y|=2$ $\Rightarrow x=y+2$ or $x=y-2$
2.4) if $x-y \notin \mathbb{Q} $ and $y-x \in \mathbb{Q} $ then $2=|y-x|$ $\Rightarrow x=y+2$ or $x=y-2$
3) $d(x,y) \le d(x,z) + d(z,y) \,,\forall x,y,z\in \mathbb{Q}  \Rightarrow$
So do I have to write all of these and prove inequalities like: $|x-y| \le |x-z| + |z-y|$ or is there any other option?
If anyone can help me with the 3rd condition and check all the previous ones, if I didn't make any mistakes (or is it wrong?), I would be really thankful.
 A: If $x,y\in[0,1]$, then $d(x,y)=d(y,x)$ because $x-y\in\mathbb{Q}\iff y-x\in\mathbb Q$.
If $x,y,z\in[0,1]$, we have several possibilites:


*

*if $x-y,y-z\in\mathbb Q$, then $x-z\in\mathbb Q$ and it is clear then that $d(x,z)\leqslant d(x,y)+d(y,z)$.

*if $x-y\in\mathbb Q$ and $y-z\notin\mathbb Q$, then $x-z\notin\mathbb Q$ and$$d(x,z)=2\leqslant|x-y|+2=d(x,y)+d(y,z).$$The same argument holds if $x-y\notin\mathbb Q$ and $y-z\in\mathbb Q$.

*If $x-y,y-z\not\in\mathbb Q$ and $x-z\in\mathbb Q$, then$$d(x,z)=|x-y|\leqslant4=d(x,y)+d(y,z).$$

*If $x-y,y-z,x-z\not\in\mathbb Q$, then$$d(x,z)=2\leqslant2+2=d(x,y)+d(y,z).$$

A: Proof for the triangle inequality. We consider two cases.
1) If $x-y\in\mathbb{Q}$ then $x,y\in [0,1]$ implies that $|x-y|\leq 2$ and $|x-y|\leq d(x,y)$. Hence
$$d(x,y)=|x-y|\leq |x-z|+|z-y|\leq d(x,y)+ d(y,z).$$
2) If $x-y\not\in\mathbb{Q}$ then $x-z\not\in\mathbb{Q}$ or $y-z\not\in\mathbb{Q}$. Therefore $d(x,z)=2$ or $d(y,z)=2$ and
$$d(x,y)=2\leq d(x,z)+ d(y,z).$$
P.S. We can replace $2$ with any number greater or equal to the length of the interval $[0,1]$ (otherwise the triangle inequality does not hold).
