$\DeclareMathOperator{\lcm}{lcm}$ Fiddling with numbers I realized that for positive integers $x$ and $y$, the quantity $$\Vert x,y \Vert=\frac{\lcm(x,y)}{\gcd(x,y)}$$ has these properties:

  • $\Vert x,y \Vert=1\iff x=y$;
  • $\Vert x,y \Vert \leq\Vert x,z\Vert\Vert z,y \Vert$ for any positive integer $z$.

In particular $\log\Vert x,y \Vert$ defines a metric over $\mathbb{N}^*$.

I couldn't find anything related online. Does anyone know if this $\Vert\cdot,\cdot\Vert$ operator appears somewhere in the literature? Or at least does it remind you of something, perhaps related to $p$-adic numbers?

  • 3
    $\begingroup$ I wonder if this metric gives the product topology on $\widehat{\mathbb Z} = \prod \mathbb Z_{(p)}$. $\endgroup$
    – LSpice
    Jan 4 at 18:35
  • 8
    $\begingroup$ It ($\log ||\cdot||$) is the sum of all p-adic metrics. $\endgroup$ Jan 4 at 18:43
  • 8
    $\begingroup$ Calling $\nu_p(x)$ the exponent of $p$ in the decomposition of $x$ as a product of prime numbers, one has $$\log\Vert x,y \Vert = \sum_{p \in \mathbb{P}} \log p \times |\nu_p(y)-\nu_p(x)|.$$ $\endgroup$ Jan 4 at 18:49
  • 7
    $\begingroup$ $d(x,y)=\sum_p|\nu_p(x)-\nu_p(y)|\log p$, so it's a "weighted" (but it's irrelevant, since every weight produces equivalent metric) taxicab metric on $c_{00}(\mathbb N)$, the space of eventually zero sequences of natural numbers $\endgroup$
    – te4
    Jan 4 at 18:50
  • 3
    $\begingroup$ @DmitriiKorshunov it's not just a sum. Each one is weighted by $\log p$. $\endgroup$ Jan 4 at 18:52

3 Answers 3


This metric is mentioned in the Encyclopedia of distances (Chapter 10.3), written by Michel Marie Deza and Elena Deza. Here is the relevant paragraph:$\newcommand{\lcm}{\operatorname{lcm}}$

Let $\mathbb{L}= (L,\preceq,\vee, \wedge)$ be a lattice, and let $v$ be an isotone subvaluation on $\mathbb{L}$. The lattice subvaluation semimetric $d_v$ on $L$ is defined by $$2v(x \vee y)-v(x)-v(y).$$ (It can be defined also on some semilattices.) If $v$ is a positive subvalution on $\mathbb{L}$, one obtains a metric, called the lattice subvaluation metric. If $v$ is a valuation, $d_v$ is called the valuation semimetric and can be written as $$v(x \vee y)-v(x \wedge y)=v(x)+v(y)-2 v(x \vee y).$$ If $v$ is a positive valuation on $\mathbb{L}$, one obtains a metric, called the lattice valuation metric, and the lattice is called a metric lattice.

If $L= \mathbb{N}$ (the set of positive integers), $x\vee y= \lcm(x,y)$ (least common multiple), $x\wedge y = \gcd(x,y)$ (greatest common divisor), and the positive valuation $v(x)= \ln x$, then $d_v(x,y)= \ln \frac{\lcm(x,y)}{\gcd(x,y)}$.

This metric can be generalized on any factorial (i.e., having unique factorization) ring equipped with a positive valuation $v$ such that $v(x) \geq 0$ with equality only for the multiplicative unit of the ring, and $v(xy)=v(x)+v(y).$ Cf. ring semimetric.

  • 7
    $\begingroup$ (I found the same source by googling "lcm(x,y)/gcd(x,y)" "metric") $\endgroup$ Jan 5 at 7:51

As indicated by @MartinSleziak the function

$$f(x,y):=\frac{xy}{\gcd(x,y)^2} = \frac{\operatorname{lcm}(x,y)}{\gcd(x,y)}$$

has interesting properties for example as indicated in this question about the abc conjecture:

$$k(x,y):=1/f(x,y) = \frac{\gcd(x,y)^2}{xy}$$

is a positive definite kernel over the natural numbers.

(This can be seen directly by mapping the natural numbers into the Hilbert space of series as is being done in this question : Let $e_d$ be the $d$-th standard-basis vector in the Hilbert space $H=l_2(\mathbb{N})$. Let $h(n) = J_2(n)$ be the second Jordan totient function, defined by:

$$J_2(n) = n^2 \prod_{p|n}(1-1/p^2).$$ Define:

$$\phi(n) = \frac{1}{n} \sum_{d|n}\sqrt{h(d)} e_d.$$

Then we have:

$$ \left < \phi(a),\phi(b) \right > = \frac{\gcd(a,b)^2}{ab}=:k(a,b).)$$

Another usage of the function $f$ that you indicate is to make the unitary divisors into a boolean ring:

Let $n$ be a natural number, $U_n := \{ d \mid d \text{ divides } n, \gcd(d,n/d)=1\}$ be the set of unitary divisors.

We can make $U_n$ into a boolean ring:

$$a \oplus b := \frac{ab}{\gcd(a,b)^2} = \frac{\operatorname{lcm}(a,b)}{\gcd(a,b)}$$ and $$a \otimes b := \gcd(a,b).$$

Yet another nice proof, that the function $k$ is positive definite over the natural number, comes from Rodrigo's answer to Trigonometry / Euclidean Geometry for natural numbers?.

I have used this kernel to define the simplicity of ratio in music consonance: Measuring Note Similarity With Positive Definite Kernels and generate algorithmic music based on this (Sound of the nearest neighbors).

Another usage of this or related kernel is to generate formulas for the circle number $\pi$ as is being indicated here: Some Formulas For Pi.


Not an answer, but I was curious about the "shape" of numbers determined by this metric. Here's a t-SNE plot of the numbers from 1 to 256. As with any projection of this type, the geometry is quite distorted. But you can still make out some interesting structures, as in the cluster of numbers of the form $2^a3^b$ at lower right.

The numbers are colored by the log of the smallest prime factor. (Large primes faded out a bit, but you get the idea.)

enter image description here

  • 1
    $\begingroup$ Nice plot, You could also try UMAP for this. $\endgroup$ Jan 5 at 12:15
  • $\begingroup$ It's interesting, I did try UMAP, and it had the same basic structure but the results were harder to read. For instance, the large primes all ended up in a kind of one-dimensional linear structure, which seemed slightly deceptive. $\endgroup$ Jan 5 at 12:27
  • 1
    $\begingroup$ You might be interested in this plot: johnhw.github.io/umap_primes/index.md.html $\endgroup$ Jan 5 at 12:31
  • 1
    $\begingroup$ Such a cool picture! And it seems like the metric there is in the same general family as this one, especially for square-free numbers. $\endgroup$ Jan 5 at 12:47
  • $\begingroup$ Yes it looks like some sort of galaxy and yet these are "just" natural numbers! :-) Very cool. $\endgroup$ Jan 5 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.