Proving a function is a metric Define a function $d : \mathbb{Z × Z \to R}$ by setting $d(x, x) = 0$ for all $x ∈ \mathbb{Z}$, and if $x \ne y$, setting $d(x, y) = 3^{-k}$ where $3^k$ is the largest power of $3$ dividing $x − y$. Prove that $d$ is a metric on $\mathbb{Z}$.
I've proven the first three parts needed to show it's a metric, but I can't figure out how to prove the triangle inequality for the function.  I know I have to show $d(x,z) \le d(x,y) + d(y,z)$, but I'm confused about how I do that for this function. 
 A: Let's write $x-y$ as $3^k m$, where $3$ is coprime to $m$, and similarly set $y-z$ = $3^j n$. Assume without loss of generality that $k \le j$; then $x-z$ = $3^k(m + 3^{j-k}n)$. Why does this solve your problem?
(I suggest you handle separately the cases where $k = j$ and $k < j.$)
A: This is the $3$-adic metric. We can simplify the question to proving that the $3$-adic norm $|0|_3=0$, $|x|_3=3^{-\nu_3(x)}$ (where $\nu_3(x)$ is the largest power of $3$ dividing $x$) is a norm, meaning that $|x|_3=|{-x}|_3$, $|x|_3=0\iff x=0$,  $|x+y|_3\le|x|_3+|y|_3$ (the usual definition of norm includes $|xy|_3=|x|_3|y|_3$, but we don't need this for the metric claim). The important property of $\nu_3(x)$ that we need is that $n\le\nu_3(x)$ iff $3^n\mid x$.
In fact, it is an ultrametric: $|x+y|_3\le\max(|x|_3,|y|_3)$. The claim is trivial if any of $x,y,x+y$ is zero, so suppose they are all nonzero. Then equivalently we want to show $\min(\nu_3(x),\nu_3(y))\le\nu_3(x+y)$, or $k\le\nu_3(x)\land k\le \nu_3(y)\implies k\le\nu_3(x+y)$. Unfolding the definition of $\nu_3$ this means that $3^k\mid x$ and $3^k\mid y$ implies $3^k\mid x+y$, which is an elementary property of divisibility.
Note that this entire analysis remains valid if $3$ is replaced with any integer $p>1$, which yields the $p$-adic metrics (although you need to assume $p$ is prime for the aforementioned identity $|xy|_p=|x|_p|y|_p$).
