Hamming cube as an L1 and L2 metric Created 2026-09-28 Updated 2026-10-14
Use the convention for the Hamming cube . Its elements are length- binary strings, and their Hamming distance counts the differing coordinates:
Send each binary string to the vector with the same coordinates, by . Every differing coordinate contributes both to the sum of absolute differences and to the sum of squared differences. Therefore the L1 norm and L2 norm give, respectively,
This short coordinate calculation proves that the L1 norm gives an isometric embedding, while Euclidean distance grows like the square root of the number of changed binary digits. For example, and differ twice: their Hamming distance and Manhattan distance are , but their Euclidean distance is . Comparing binary strings in these two geometric representations answers different questions even though the points have the same coordinates.
For distinct pairs ranges over every integer from to . The metric embedding into the L2 norm thus has sharp ratios
Neighbors attain and opposite corners attain . This computes the bi-Lipschitz distortion of this coordinate map; it does not prove that every metric embedding into an L2 space has at least this bi-Lipschitz distortion. Uniformly multiplying the output coordinates changes and together and leaves unchanged.
Figure 1.
Hamming distances become k in L1 and square root of k in L2, with controls independent of dimension
. Details.
The important family distinction is that these coordinate maps have no dimension-independent bound on their bi-Lipschitz distortion into the L2 norm, yet they do give a uniform coarse embedding of a family of metric spaces. Pad each output vector with zero coordinates to view all maps in the single l2 sequence space, an L2 space for counting measure. Then the same functions
work for every , and . Similarly, padding into the l1 sequence space gives common controls and exact preservation of Hamming distance. These claims use unnormalized Hamming distance; replacing it by normalized Hamming distance changes the family of source metrics.
The geometry has a practical origin: Hamming's 1950 paper uses the number of differing positions between binary strings to study error-correcting codes. Changing one binary digit moves to a neighboring corner, so a question about corrupted messages becomes a question about separation in the Hamming cube. [ref]
Jaccard distance 2026-10-14
The dissimilarity is the number of mismatched presences divided by the number of coordinates present in at least one profile. It differs from normalized Hamming distance because coordinates absent from both profiles do not enter its denominator. Define the distance of two empty sets to be zero.
The displayed distance is the normalized Hamming distance. Each coordinate mismatch between implies a mismatch between or , so summing the indicator inequalities proves the triangle inequality. Nonnegativity, symmetry and separation follow immediately. It is a metric on profiles; on separately labelled individuals with identical profiles it is a pseudometric.
Normalized Hamming distance Created 2026-10-07 Updated 2026-10-14
On binary words of length , normalized Hamming distance is the fraction of differing coordinates. Unlike unscaled Hamming distance, it makes the Hamming cubes a Lévy family under uniform probability measures.
Treat each row as a set of attributes with response one. The binary option computes the Jaccard distance, rather than counting matches at joint absences. For a pair of rows, let count coordinates equal to one in both, count , count , and count . Then
The denominator counts coordinates present in at least one row; joint absences do not contribute. If both rows have no presences, use distance zero. This differs from normalized Hamming distance, which would divide by all ten coordinates.
For Philip and Chad, four attributes are present in both and eight in at least one, giving Jaccard distance . Graham and Tim differ in one of eight coordinates present in their union, giving , printed as . Fred and Gbenga have identical profiles, hence distance zero despite being different students. The resulting dissimilarity matrix is symmetric with zero diagonal; dist2full restores the other half and the diagonal from the stored pairwise entries. The display rounds entries for readability; the agglomerative hierarchical clustering uses the original unrounded distances.
The first command reads a rectangular data file into a; header=T treats the first line as variable names. There are twelve observations, identified by student names, and nine binary attributes. A one records presence of an attribute and a zero records absence. This is a description of the encoding, not a claim that every presence is equally important for a scientific application.
dist(a, metric="binary") compares rows using Jaccard distance. If counts shared presences and count mismatched presences, then
Joint absences do not enter the denominator, unlike the simple matching coefficient or normalized Hamming distance. dist2full(d) expands the stored pairwise distances into a symmetric dissimilarity matrix; round(...,2) changes only its displayed precision. The clustering command still receives the original unrounded distances.
For example, Tom and Martin have six shared presences and only one mismatch, giving . Taeko and Luitgard have three shared presences and four mismatches, giving . LingChen and Mohammad share only the meat attribute and differ on four others, giving . The diagonal is zero, and the entries are symmetric because exchanging the two observations exchanges and .
hclust(d, method="compact") constructs an agglomerative hierarchical clustering object by complete-linkage clustering. Its distance between two current groups is
Start with singleton groups, merge a pair with smallest intergroup distance, update these maximum cross-pair distances, and repeat until one group remains. The object stores the merge structure, merge heights and a leaf order suitable for a dendrogram; assigning it to h does not itself display a graph. The historical S-Plus help identifies compact with complete linkage and describes the plotting object.
The first merge is Tom with Martin at . At the next height , either LinYee with HuiChin or HuiChin with Meg may merge: the distances are tied. The following dendrogram shows one valid resolution, using original row order to resolve ties. In this tree, LinYee joins HuiChin at , Pio joins Meg at , and Nicolas joins Tom–Martin at . The latter height is , illustrating the complete-linkage update.
Figure 1.
Complete-linkage dendrogram and Jaccard-distance heatmap for the binary student profiles, with one valid tie convention
. Details.
For the displayed tree, a cut at height gives three groups: Taeko–Luitgard; Alet–Tom–Martin–Nicolas–Mohammad; and LinYee–Pio–LingChen–HuiChin–Meg. The last two merges occur at and . The hierarchy is a description under the chosen binary distance and linkage rule; it neither supplies an intrinsically correct number of groups nor guarantees a unique tree in the presence of ties. Changing the treatment of joint absences, or the weighting of attributes, can change that description.
A metric dissimilarity must satisfy nonnegativity, separation, symmetry and the triangle inequality:
The underlying objects must be specified: here they are binary measurement profiles, rather than labels attached to individuals.
Let count coordinate pairs of the indicated types. The simple matching coefficient is , so its complementary dissimilarity is . Counting mismatches in every pair gives the dissimilarity matrix
For the Jaccard coefficient, joint absences are excluded: . Thus the Jaccard distance is , giving
Only the pair of individuals two and four has a joint absence. Their profiles have one shared presence, two mismatched presences and one joint absence, giving dissimilarities and , respectively. All other pairs have a presence in at least one profile at every coordinate, so the two denominators coincide.
For the requested metric property of simple matching dissimilarity, write a general pair of -coordinate binary profiles as . Then
which is the normalized Hamming distance. It is nonnegative and symmetric, and equals zero exactly when all coordinates match. For each coordinate, a mismatch between and forces a mismatch between or between . Therefore
Summing and dividing by proves the triangle inequality, establishing all four metric properties. Simple matching dissimilarity is a metric on binary profiles. If two separately labelled individuals have identical profiles, it gives zero distance between them, so on those labels it is only a pseudometric. The four profiles here are distinct, so this distinction does not prevent from defining a metric on the given sample.
For fixed , the complement of the simple matching coefficient is the fraction of coordinates that disagree:
This is the normalized Hamming distance. It is nonnegative, symmetric, and is zero exactly when every coordinate agrees. At each coordinate,
Summing and dividing by proves the triangle inequality. Therefore is a metric on the binary vectors.
Identify the hypercube graph with , joining two sets when their symmetric difference has size one. Write for the closed graph neighbourhood of , and for its radius- neighbourhood in Hamming distance. In the simplicial order on the discrete cube, smaller sets come first, with lexicographic order within each rank: the smallest differing coordinate belongs to the earlier set. Let be the first vertices in this order. Harper theorem is
Equivalently, minimizes the external vertex boundary at fixed size. We will also obtain for every integer .
Here is a complete proof by simplicial section compression. First note two properties of the simplicial order on the discrete cube. Its restriction to either face obtained by fixing one coordinate is the corresponding order on the smaller hypercube graph. Also, the closed graph neighbourhood of an initial segment is an initial segment. To verify the latter, a nonempty initial segment contains every level below its last level , and a lexicographic prefix at level . For , its closed graph neighbourhood contains every set of size at most , and its only further members are the upper shadow of . An -set lies in this upper shadow exactly when its lexicographically earliest -subset lies in . That earliest subset is obtained by deleting the largest element. These earliest subsets vary monotonically in lexicographic order, so the upper shadow is another lexicographic prefix. For , the closed graph neighbourhood of is the union of levels zero and one. The empty initial segment causes no exception.
Induct on , with immediate. Fix a coordinate and write the sections of as , deleting from the latter section. Replace them by the initial segments with , . The sections of the old closed graph neighbourhood are
By induction their sizes are at least and , respectively. These are exactly the sizes of the new sections, because both sets in each new union are initial segments and hence nested. Thus simplicial section compression preserves size and never enlarges the closed graph neighbourhood.
Repeatedly compress any section that is not already an initial segment. Every change strictly reduces the sum of the global simplicial positions of the included vertices. This nonnegative integer decreases only finitely often, so the process ends at a family whose sections in every coordinate are initial segments. If itself is an initial segment, the induction is complete. Otherwise choose the earliest absent vertex and the latest present vertex , with . They cannot agree in any coordinate: agreement would put them in one compressed section, where an earlier absent vertex cannot precede a later present one. Hence . Nor can a vertex lie between them: if is present, pairing it with would force ; if absent, pairing it with would force . Thus are consecutive, and is obtained from by replacing its last vertex with the next vertex .
There are only two possibilities for these terminal families for simplicial section compression. If , consecutiveness makes the last -set and the first -set. Complementarity forces , and . For , the corresponding contains all sets of size at most except , and additionally . Every -set has at least two -subsets, so at least one belongs to . The missing has a -subset in . Consequently contains every set of size at most , which is exactly .
If , then . Since are complementary, the smaller one contains coordinate . Consecutiveness forces to be the last -set containing , and the first -set avoiding :
The initial segment consists of all sets of size less than and all -sets containing . Its closed graph neighbourhood contains all sets of size at most and all -sets containing . For , each such -set has -subsets containing , so removing only leaves one in . All sets of size at most are still in , because all levels below belong to . Hence again . For , the two families are related by exchanging coordinates and both have the whole as their closed graph neighbourhood. These comparisons finish the induction and prove Harper theorem.
For the radius- version, repeatedly use the one-step result. At each step the comparison family remains an initial segment, and its closed graph neighbourhood is monotone in its size. If , applying Harper theorem to therefore gives . Induction on proves the asserted extension.
A Lévy family of graphs has vanishing concentration of measure functions after distances have been scaled by the graph diameter. More explicitly, for connected finite graphs of diameter , use normalized graph distance and uniform probability measure. For every fixed , require
For this normalization is normalized Hamming distance , since its diameter is .
If , the corresponding initial segment contains the Hamming ball about of radius . The radius- version of Harper theorem implies
Use the precise Hoeffding inequality for . One can also derive this estimate directly: the moment-generating function of is ; the exponential Markov inequality followed by minimization at gives the bound. With , we have . Thus, whenever ,
This proves that the hypercube graphs form a Lévy family of graphs. The stronger fixed-positive-mass formulation follows as well. For any , choose with . The Chebyshev inequality for , whose variance is , makes the Hamming ball of radius have fewer than vertices. An initial segment of size at least contains that ball. Enlarging by and using the same Hoeffding inequality gives a complement proportion tending to zero uniformly over all such . The normalization matters: with unscaled unit Hamming distance, cubes do not satisfy the metric version at every fixed radius; for a radius below one, a half-cube has no enlargement.
Equality in Harper theorem does not determine a down-set up to isomorphism. In , take
This is a down-set of size nine. Its closed graph neighbourhood contains every set of size at most two, because all singletons belong to . Every triple contains an edge of the four-cycle among the listed pairs, so every triple also belongs to . The four-element set does not. Hence .
The size-nine simplicial order on the discrete cube initial segment is all sets of size at most one together with the pairs . Every triple contains one of these pairs, and the four-element set is again absent from its closed graph neighbourhood. Its neighbourhood therefore also has size , proving extremality of . Nevertheless the induced graphs are not isomorphic: in , the empty set has degree four, the four singletons have degree three, and the four pairs have degree two. The initial segment has two vertices of degree four, namely and . Since a graph automorphism preserves induced degree of a vertex, no automorphism of the cube can carry one family to the other. This gives nonunique down-set extremizers for Harper theorem even under the stronger test of induced graph isomorphism.
For binary vectors, this similarity counts agreements on both presences and absences. Its complement is the normalized Hamming distance. Whether joint absences should count as similarity depends on the application; rare-presence data may call for a different coefficient.