I am try to transform a decimal number into a binary form but still keep distance information. Such as 10-2=8 in euclidean space, but in binary case, hamming(1010-0010)=1, obviously the distance information lost a lot. Is there any possible way to transform 10 into a binary form but still keep distance property in hamming distance metric? The naive way is hamming(1111111111-0000000011)=8....
Asked
Active
Viewed 84 times
-2
-
1You didn't lose information by converting to binary: 1010 - 0010 is still 1000. You lost information by deciding to compute the popcount of 1000 rather than using its numeric value. – Jul 30 '16 at 14:56
1 Answers
0
You have found what is basically the only distance preserving map from the metric space of nonnegative integers with distance d(x,y) = |x-y|
to the metric space of bit vectors with the hamming distance.
This isn't hard to prove: d(x,0) = x
, so the transform of x
must have x
bits set. Similarly, if x<y
, then the bits set in the transform of x
must be a subset of the bits set in the transform of y
.
So what you constructed is basically your only option if you really and truly must work in the space of bit vectors and hamming distance.
-
Thank you for your reply, actually I thought might be the best way to transform without any information lose. I think I can accept a little bit distance lose, maybe, but I will try to find a more good coding way for that. Thank you very much. – Hx Yung Jul 30 '16 at 22:31
-
@Hx: I think if you pose as a separate question what programming problem you were trying to solve by doing this, you'd get useful responses. – Jul 31 '16 at 00:43