Indexing objects like elements of a Cantor Set or nodes of a Binary Tree can result in a enconding system of binary strings like illustrated bellow:
The illustrated indexes form a finite set, $$C_3=\{0,00,000,001,... ,111\}$$
We can provide the set $C_3$ of a comparison operation, offering the same elements in a sequence with the lexicographical order (also illustred with the sequence into square breakets), that is a total order relation.
The same set can be mapped into a set of numerical pairs (bitLength,value), $$V_3=\{(1,0), (2,0), (3,0), (3,1), (2,1), ... , (3,7)\}$$
where 0=(1,0), 00=(2,0), 000=(3,0), 001=(3,1), 01=(2,1), ... etc. Any element $x$ is a pair $(x_{bitLength},x_{value})$. A generic $V_k$ have elements with $bitLength \le k$. In fact this generic set was defined in this other question as:
$$V_k = \{\forall x = (l,n) ~|~ l,n \in \mathbb{N} ~\land~ bitLength(n) \le l \le k \}$$
where the function $bitLength(n>0)=\lceil log_2(n)+1 \rceil$ and the bit-length of zero is one.
Now we can express a distance $d(x,y,k)$ of two elements $x$ and $y$ of $V_k$, that can be used as mathematical reference to the lexicographical order... What is the $d(x,y,k)$ function?
How to proof that is the correct function for any $k$?
... Or more simples, What the comparison function $cmp(x,y,k)$?
There are no special "metric", the aim is to sort, that is, to check the value of comparison. As usual convention is $cmp(x,y,k)=1$ when $x>y$, $cmp(x,y,k)=0$ when $x=y$ and $cmp(x,y,k)=-1$ when $x>y$.
NOTES
Supposing that there are someting as dyadics that can be used in the proof... Seems good in some tests, but I do not know how use mathematical foundations or how to proof:
d(x,y) = x.value/2^x.bitLength - y.value/2^y.bitLength
Some raw data to tests, illustrating with all elements of $C_4$ and $V_4$:
(bits,value) Binary representation
(1,0) 0
(2,0) 00
(3,0) 000
(4,0) 0000
(4,1) 0001
(3,1) 001
(4,2) 0010
(4,3) 0011
(2,1) 01
(3,2) 010
(4,4) 0100
(4,5) 0101
(3,3) 011
(4,6) 0110
(4,7) 0111
(1,1) 1
(2,2) 10
(3,4) 100
(4,8) 1000
(4,9) 1001
(3,5) 101
(4,10) 1010
(4,11) 1011
(2,3) 11
(3,6) 110
(4,12) 1100
(4,13) 1101
(3,7) 111
(4,14) 1110
(4,15) 1111
Some distances to test:
- d(
00,01) = d(10,11) - |d(
000,0)| = |d(1,111)| - d(
1101,11) < d(1100,1101) - ...
