---
title: Projected Hamming Distance
url: https://www.emergentmind.com/topics/projected-hamming-distance
type: topic
---

# Projected Hamming Distance

Searching arXiv for the provided topic and cited works.
Projected Hamming distance denotes a family of constructions in which Hamming distance is decomposed, induced, or approximated through a projection mechanism rather than used only in its standard symmetric, unweighted form. Across the literature, the term covers several distinct but related ideas: coordinate-wise decomposition of digit changes in base-\(n\) representations [1203.4547], learned projections from continuous embeddings into binary hash codes whose induced Hamming distances are optimized against similarity targets [1810.01008], query-dependent masking in binary code space that yields an asymmetric projected Hamming dissimilarity [2103.14455], and randomized dimension-reduction maps from high-dimensional Hamming spaces to lower-dimensional Hamming sketches that approximately preserve pairwise distances [2504.14723]. A further line of work studies projection-based approximations to Hamming distance in strings and streams [1512.04515], [1602.07241], and sublinear projection access models for estimating matrix Hamming distance [2107.02666]. Taken together, these formulations show that “projection” may refer to per-coordinate aggregation, learned binarization, query-conditioned masking, or randomized sketching, depending on the problem setting.

## 1. Conceptual scope and definitions

The classical Hamming distance between equal-length strings \(S_1=s_1s_2\dots s_k\) and \(S_2=t_1t_2\dots t_k\) is
\[
H(S_1,S_2)=\#\{i:1\le i\le k,\ s_i\ne t_i\}
\]
or equivalently
\[
H(S_1,S_2)=\sum_{i=1}^k [s_i\ne t_i].
\]
This additive form already exposes a projection viewpoint: each coordinate contributes either \(0\) or \(1\) independently to the total distance [1203.4547]. In that sense, a projected Hamming formulation may be understood as any representation in which the full distance is recovered or approximated from coordinate-local contributions, projected coordinates, or projected embeddings.

In the learning-to-hash setting, the projection is a learned map
\[
f_\theta:\mathcal{X}\to\{-1,+1\}^n,\quad
f_\theta(x)=\operatorname{sgn}\!\left(\frac{y(x)}{\|y(x)\|_2}\right),
\]
and the induced distance
\[
d_H^\theta(x^i,x^j)=d_H(f_\theta(x^i),f_\theta(x^j))
\]
is the Hamming distance in the projected space [1810.01008]. Here the projection is nonlinear, parameterized by a differentiable model, and optimized so that the projected Hamming geometry matches a target similarity relation.

In collaborative filtering, the term is used more literally for a projection-induced dissimilarity on binary codes. For \(z_u,z_i\in\{-1,1\}^m\), the projected Hamming dissimilarity is defined by
\[
\delta(z_u,z_i)=\|z_u-(z_u\cdot z_i)\|_H,
\]
with projection operator \(z_u\cdot z_i=z_u\;\text{AND}\; z_i\), giving the concrete implementation
\[
\delta(z_u,z_i)=\text{SUM}\big(z_u\;\text{XOR}\;(z_u\;\text{AND}\; z_i)\big)
\]
and equivalently
\[
\delta(z_u,z_i)=\text{SUM}\big(z_u\;\text{AND}\;(\text{NOT}\;z_i)\big)
\]
[2103.14455]. This construction is asymmetric and query-conditioned.

In randomized sketching, projection refers to a map
\[
f:\{0,1\}^d\to\{0,1\}^k
\]
or to random sign projections into Euclidean space, with the property that the Hamming distance between projected objects approximates the original Hamming distance [2504.14723], [2107.02666]. This suggests that the phrase “projected Hamming distance” is not a single formal object, but a family of distance constructions sharing the idea that Hamming geometry is obtained after an explicit projection step.

## 2. Coordinate projections and base-\(n\) digit structure

A foundational projection-style interpretation appears in the study of Hamming distance between base-\(n\) representations of whole numbers [1203.4547]. A non-negative integer
\[
m=\sum_{i=0}^k a_i n^i,\quad 0\le a_i\le n-1
\]
is represented as \((a_k a_{k-1}\dots a_0)_n\), and comparisons use leading-zero padding so that base-\(n\) strings have equal length. The resulting Hamming distance between integers \(x\) and \(y\) is the Hamming distance between their padded base-\(n\) expansions [1203.4547].

The key lemma concerns consecutive integers. If \(l\) is the exponent of the highest power of \(n\) dividing \(m\), equivalently the number of trailing zeros in the base-\(n\) expansion of \(m\), then
\[
H(m,m-1)=l+1.
\]
The paper proves this by separating the cases \(m=n^l\), \(m=pn^q\) with \((p,n)=1\), and \(n\nmid m\) [1203.4547]. The result identifies exactly how many coordinates change when incrementing by one: the trailing zero run and the next digit above it.

This local characterization leads to a global sum. Defining
\[
S(m)=\sum_{i=0}^{m-1} H(i,i+1),
\]
and writing \(P_i\) for the exponent of the highest power of \(n\) dividing \(i\), one has
\[
S(m)=\sum_{i=1}^{m}(P_i+1).
\]
Using the identity
\[
P_i+1=\sum_{j=0}^\infty [n^j\mid i],
\]
the paper rewrites the total as
\[
S(m)=\sum_{j=0}^{\lfloor \log_n m\rfloor}\left\lfloor\frac{m}{n^j}\right\rfloor
\]
up to the paper’s noted typesetting issue regarding floor versus ceiling [1203.4547].

This is a genuine coordinate-projection decomposition. If
\[
H(i,i+1)=\sum_{j\ge 0} h_j(i),
\]
where \(h_j(i)\in\{0,1\}\) indicates whether digit position \(j\) changes between \(i\) and \(i+1\), then
\[
S(m)=\sum_{j\ge 0}\sum_{i=0}^{m-1} h_j(i),
\]
and
\[
\sum_{i=0}^{m-1} h_j(i)=\left\lfloor \frac{m}{n^j}\right\rfloor
\]
[1203.4547]. In this formulation, projected Hamming distance is the sum of per-digit change counts, and the arithmetic structure of divisibility by powers of \(n\) determines which coordinate projections contribute.

A common misconception is that this construction depends essentially on \(n>2\). The abstract states \(n>2\), but the main text allows \(n\ge 2\), and the extracted discussion states that nothing in the proofs breaks at \(n=2\); binary is simply the simplest case [1203.4547]. This suggests that the projection interpretation is base-agnostic once padding and coordinate-wise comparison are fixed.

## 3. Learned projections into Hamming space

In neural hashing, projected Hamming distance arises from a learned projection from input space into the Hamming cube [1810.01008]. For an input \(x\), the model produces a real embedding
\[
y(x)=(y_1(x),\dots,y_n(x)),
\]
normalizes it to the unit sphere,
\[
z(x)=\frac{y(x)}{\|y(x)\|_2},
\]
and binarizes by sign:
\[
\text{hash}(x)=\operatorname{sgn}(z(x))\in\{-1,+1\}^n.
\]
The central objective is to make the Hamming distance between binary codes reflect a target similarity relation specified by a similarity matrix \(S\in\{0,1\}^{b\times b}\) and a Hamming radius \(r\) [1810.01008].

The geometric model links angle on the sphere to Hamming distance. For normalized embeddings \(z^i,z^j\), with angle \(\theta\) satisfying
\[
z^i\cdot z^j=\cos\theta,
\]
the probability that a bit differs is modeled as
\[
P_{ij}=\frac{\theta}{\pi}=\frac{\arccos(z^i\cdot z^j)}{\pi}.
\]
Under the simplifying assumption that bit differences are independent given the angle, the Hamming distance between codes is approximated by
\[
d_H(\text{hash}(x^i),\text{hash}(x^j))\sim \text{Binomial}(n,P_{ij}),
\]
and
\[
\Pr(d_H\le r\mid z^i,z^j)\approx F(r;n,P_{ij}),
\]
where \(F\) is the binomial CDF [1810.01008].

The loss is a log-likelihood over pairwise Hamming distance targets:
\[
J=-J_1-\lambda J_2+\lambda_w J_3,
\]
with
\[
J_1=\text{Avg}[S\circ \log F(r;n,P)],
\]
\[
J_2=\text{Avg}[(1-S)\circ \log F(n-r-1;n,1-P)],
\]
and
\[
J_3=\|W\|_2^2
\]
[1810.01008]. Similar pairs are pushed toward small projected Hamming distance, while dissimilar pairs are pushed outside the radius \(r\).

The paper’s training scheme is also projection-aware. Batches are partitioned into groups of size \(g\), each formed around a “marker” input and \(g-1\) similar examples, and the loss is evaluated over all pairs in the batch [1810.01008]. This produces a better estimate of pairwise geometry in projected Hamming space than naive minibatch sampling.

The same work couples the learned distance with multi-indexing. For \(n\)-bit codes and radius \(r\), the code is split into \(m=r+1\) substrings, each stored in its own hash table. By pigeonhole principle, any code within Hamming distance \(r\) must match the query exactly in at least one substring, yielding complete retrieval within the radius after candidate filtering [1810.01008]. The expected lookup cost under uniform code distribution is analyzed as
\[
\text{cost}\sim (r+1)\cdot \frac{N}{2^{n/(r+1)}},
\]
with the recommendation
\[
\frac{n}{r+1}\approx \log_2 N
\]
[1810.01008].

Empirically, the method reports strong retrieval performance on ImageNet and SIFT 1M, but the conceptual significance for projected Hamming distance lies in the explicit probabilistic coupling between continuous geometry and discrete distance. The expected normalized Hamming distance is
\[
\mathbb{E}\left[\frac{d_H}{n}\right]\approx \frac{\theta_{ij}}{\pi},
\]
so the learned projection compresses angular geometry into Hamming geometry in a controlled way [1810.01008].

## 4. Query-dependent projection and bit-level importance coding

A distinct formalization appears in collaborative filtering, where projected Hamming dissimilarity is introduced to overcome the equal-weight limitation of ordinary Hamming distance on binary codes [2103.14455]. Standard Hamming distance for \(z_u,z_i\in\{-1,1\}^m\) is
\[
d_H(z_u,z_i)=\sum_{j=1}^m \mathbf{1}[z_u^{(j)}\ne z_i^{(j)}]
=\text{SUM}(z_u\;\text{XOR}\;z_i),
\]
which is symmetric and assigns identical importance to each bit [2103.14455].

The paper instead defines a field-agnostic projected dissimilarity
\[
\delta(\vec{u},\vec{i})=\|\vec{u}-\vec{u}\cdot \vec{i}\|,
\]
where \(\cdot\) is a projection operator satisfying linearity for fixed \(\vec{u}\) and idempotence on \(\vec{u}\) [2103.14455]. Specializing to Hamming space with \(V=\{-1,1\}^m\), field \(F=\mathbb{Z}_2\), Hamming norm, and projection
\[
z_u\cdot z_i=z_u\;\text{AND}\; z_i,
\]
gives the projected Hamming dissimilarity
\[
\delta(z_u,z_i)=\text{SUM}\big(z_u\;\text{XOR}\;(z_u\;\text{AND}\;z_i)\big)
\]
[2103.14455].

The operational interpretation is query-specific masking. Bits where the query has \(-1\) are disabled: projection forces the corresponding bit of the item to \(-1\), regardless of the item’s original value. Bits where the query has \(+1\) remain discriminative [2103.14455]. As a result, the effective importance of an item bit depends on the querying user, not on a global weight vector.

This dissimilarity is explicitly asymmetric:
\[
\delta(z_u,z_i)\ne \delta(z_i,z_u)\quad \text{in general}
\]
[2103.14455]. The paper notes that it is therefore not a metric in the usual sense. This asymmetry is not incidental; it encodes a recommendation scenario in which the query user specifies which latent properties should matter.

The same work proposes a variational hashing model optimized directly for this dissimilarity. User and item codes \(z_u,z_i\in\{-1,1\}^m\) have Bernoulli priors, variational posteriors \(q_\psi(z_u\mid u)\) and \(q_\phi(z_i\mid i)\), and an ELBO
\[
\log p(R_{u,i}) \ge
\mathbb{E}_{q_\psi q_\phi}[\log p(R_{u,i}\mid z_u,z_i)]
-\mathrm{KL}(q_\psi\|p(z_u))
-\mathrm{KL}(q_\phi\|p(z_i))
\]
[2103.14455]. The rating predictor uses projected Hamming dissimilarity through
\[
f(z_u,z_i)=g(\delta(z_u,z_i)),
\]
where \(g\) is a fixed affine map from the integer range of \(\delta\) to the rating scale [2103.14455].

A notable property is that projected Hamming dissimilarity can be computed with the same online complexity as standard Hamming distance. Using
\[
\delta(z_u,z_i)=\text{SUM}\big(z_u\;\text{AND}\;(\text{NOT}\;z_i)\big),
\]
and pre-storing \(\tilde{z}_i=\text{NOT}\;z_i\), the online operation becomes AND plus popcnt, compared with XOR plus popcnt for ordinary Hamming distance [2103.14455]. The reported microbenchmark on 100M random 64-bit codes gives 0.07401 seconds for both Hamming distance and projected Hamming dissimilarity, versus 4.71414 seconds for a 64-dimensional floating-point inner product [2103.14455].

The reported collaborative-filtering gains are up to +7% in NDCG and +14% in MRR over Hamming-based baselines, with no additional storage and no computational overhead compared to ordinary Hamming distance [2103.14455]. Those empirical gains are specific to the paper’s recommendation setting; the broader conceptual point is that projected Hamming distance can encode binary importance weighting without leaving Hamming space.

## 5. Randomized projections, sketches, and approximation

Another major interpretation uses random projections from a high-dimensional Hamming space into a lower-dimensional Hamming space or Euclidean sketch space, with approximate distance preservation [2504.14723], [1512.04515], [1602.07241], [2107.02666].

In the all-pairs setting, a randomized map
\[
f:\{0,1\}^d\to\{0,1\}^k
\]
is constructed by drawing a random matrix \(F\in\{0,1\}^{k\times d}\) with i.i.d. \(\operatorname{Bernoulli}(1/(4t))\) entries and defining
\[
f(x)=F x^\top \pmod 2.
\]
For a pair \(x,y\), the single-coordinate disagreement probability in the sketch is
\[
\Pr[f^i(x)\ne f^i(y)]
=\frac12\left(1-\left(1-\frac{1}{2t}\right)^{\mathrm{ham}(x,y)}\right),
\]
which is monotone in the original Hamming distance [2504.14723]. With \(k=O(\log N/\epsilon^2)\), Chernoff concentration separates pairs with \(\mathrm{ham}(x,y)\le t\) from pairs with \(\mathrm{ham}(x,y)\ge (1+\epsilon)t\) with high probability [2504.14723]. A multiscale family of such projections yields a randomized algorithm for approximate all-pairs Hamming distances in time
\[
O\Bigl( \frac{\log N}{\delta^2}\bigl( N\log_{1+\delta} q + pr \log \log_{1+\delta} q\bigr)\Bigr),
\]
where \(N=pq+qr\) [2504.14723].

This same projected-distance machinery is then used for approximate 0–1 matrix multiplication, approximate MST construction in Hamming space, and \((2+\epsilon)\)-approximation algorithms for \(\ell\)-center and minimum-diameter \(\ell\)-clustering in \(\{0,1\}^d\) [2504.14723]. The paper does not use the term “projected Hamming distance,” but the extracted description states that its central technical tool is precisely a family of randomized projections into a lower-dimensional Hamming space [2504.14723].

In pattern matching, projection appears through random hashing of alphabet symbols. A Karloff-style estimator uses \(k=O(1/\epsilon^2)\) pairwise independent sets of 4-wise independent functions
\[
h_i:\Sigma\to\{0,1\},
\]
computes projected binary Hamming distances
\[
x_i=HAM(h_i(T_j),h_i(P)),
\]
and outputs
\[
X^*=2\cdot \frac{\sum_{i=1}^k x_i}{k}
\]
as an unbiased estimator of the true Hamming distance at alignment \(j\) [1512.04515]. The 2015 paper improves the dependence on \(\epsilon\) from \(\tilde O(1/\epsilon^2)\) to \(\tilde O(1/\epsilon)\) per alignment by identifying heavy hitter character pairs, constructing a sparse approximate mismatch matrix \(D'\), and correcting the projected estimator accordingly [1512.04515]. The core claim is that the classic projection-based variance barrier is not inherent in the pattern-to-text setting [1512.04515].

In the streaming setting, approximate Hamming distance is maintained through sketches rather than exact windows [1602.07241]. For binary alphabets, the paper gives an
\[
O(\epsilon^{-3} \sqrt{n} \log^{2} n)
\]
space algorithm with
\[
O(\epsilon^{-2} \log n)
\]
worst-case time per arriving symbol, while for general alphabets the bounds are
\[
O(\epsilon^{-5} \sqrt{n} \log^{4} n)
\]
space and
\[
O(\epsilon^{-4} \log^3 n)
\]
time [1602.07241]. The method combines binary reductions of the alphabet, JL-style sketches for blocks, and super-sketches for longer substrings [1602.07241]. The extracted discussion explicitly interprets these as constructions of projected Hamming distance in streaming and communication-constrained environments [1602.07241].

A related projection-based model appears for unknown matrices. Given oracle access to row or column inner products with vectors in \(\{0,1\}^n\), a randomized sublinear-time algorithm estimates the matrix Hamming distance
\[
D_M(A,B)=|\{(i,j): A(i,j)\ne B(i,j)\}|
\]
within \((1\pm \epsilon)\) using
\[
\tilde O\!\left(\frac{n}{\sqrt{D_M(A,B)}}\right)
\]
IP queries [2107.02666]. The method builds random sign projections of rows, applies JL-style norm preservation to row differences, and aggregates projected row-distance information through bucketing and sampling [2107.02666]. The paper also proves a matching lower bound in the IP model up to polylog factors [2107.02666].

## 6. Complexity-theoretic and algebraic perspectives

Projected Hamming distance also appears indirectly in complexity theory, where Hamming distance is shown to be complete for a large class of structured kernels and tightly related to sparse matrix multiplication [1711.03887]. The paper studies \((+,\diamond)\) products, convolutions, and matrix products for binary integer functions \(\diamond\), and proves that for non-axis-orthogonal piecewise polynomial kernels, Hamming distance is complete under one-to-polylog reductions [1711.03887].

The equivalence class includes all-pairs Hamming distances, dominance products, threshold products, odd \(\ell_{2p+1}\) distances for constant \(p\), and \((+,\max)\)-matrix product [1711.03887]. The same holds in the pattern-matching setting [1711.03887]. Since the reduction framework explicitly supports “don’t care” symbols \(\star\), inactive coordinates can be projected out by mapping them to \(\star\), which means subset-restricted or sparsified Hamming computations fit naturally into the model [1711.03887].

The same paper proves that the complexity of AllPairsHammingDistances is, up to polylogarithmic factors, equivalent to sparse rectangular matrix multiplication:
\[
Sparse\big(n,\ \min(d^2,nd),\ n;\ nd,\ nd\big)
\]
for \(n\) vectors of dimension \(d\) [1711.03887]. This result places projected or sparse Hamming computations inside a broader fine-grained complexity landscape: improvements for Hamming-type kernels imply improvements for a family of distance and order predicates, and vice versa.

A different algebraic line uses probabilistic polynomials for symmetric Boolean functions to obtain subquadratic exact algorithms for batched Hamming nearest neighbor in dimensions \(d=c(n)\log n\) [1507.05106]. The core polynomial degree bound is
\[
O\bigl(\sqrt{n\log(1/\epsilon)}\bigr)
\]
for symmetric functions on \(n\) bits, which is then specialized to Hamming-threshold predicates [1507.05106]. Although the paper does not focus on projected Hamming distance as a named object, its machinery applies whenever the distance predicate depends only on the count of differences in a selected coordinate set. The extracted discussion notes that for a fixed subset \(S\subseteq[d]\), projected Hamming distance is simply Hamming distance in dimension \(|S|\), so the same probabilistic polynomial framework applies with \(d'\!=|S|\) in place of \(d\) [1507.05106].

## 7. Properties, distinctions, and misconceptions

The literature does not support a single universal definition of projected Hamming distance. Instead, at least four technically distinct meanings recur.

First, projection may mean coordinate-wise decomposition, as in base-\(n\) digit positions contributing independently to distance sums [1203.4547]. In this sense, the projection is onto coordinate axes, and the total distance is reconstructed exactly from local indicators.

Second, projection may mean a learned map into the Hamming cube, after which ordinary Hamming distance is used in the projected space [1810.01008]. Here the projection is global, differentiable before binarization, and optimized against pairwise radius constraints.

Third, projection may mean a query-conditioned masking operator on binary codes, producing an asymmetric dissimilarity rather than a metric [2103.14455]. This is the most literal use of the phrase in the title of a paper and is the formulation most directly associated with “projected Hamming dissimilarity” as a term of art.

Fourth, projection may mean randomized dimensionality reduction or sketching, where projected Hamming distances between compressed objects approximate original distances [2504.14723], [1512.04515], [1602.07241], [2107.02666]. In these works, the point is algorithmic acceleration rather than semantic reinterpretation of bit importance.

A frequent misconception is to treat all such constructions as weighted Hamming distance. The collaborative-filtering formulation does not use real-valued weights; it uses binary weighting through disabling bits, implemented by a projection \(z_u\cdot z_i=z_u\;\text{AND}\;z_i\) [2103.14455]. Conversely, the learned-hash formulation retains standard Hamming distance after projection rather than modifying the metric itself [1810.01008].

Another misconception is to assume symmetry. Standard Hamming distance is symmetric, and the learned-hash and randomized-sketch settings preserve that property. The collaborative-filtering projected Hamming dissimilarity does not: \(\delta(z_u,z_i)\neq \delta(z_i,z_u)\) in general [2103.14455]. Any use of the term therefore requires attention to whether the object is a distance, a dissimilarity, or a surrogate probability model over distances.

Finally, not every projection-style use of Hamming distance preserves exactness. The base-\(n\) decomposition is exact [1203.4547], the collaborative-filtering masking formula is exact for its defined dissimilarity [2103.14455], and the learned-hash approach uses exact Hamming distance on projected binary codes [1810.01008]. By contrast, randomized projection and sketching methods provide \((1\pm\epsilon)\)-approximations or threshold separations with high probability [2504.14723], [1512.04515], [1602.07241], [2107.02666].

## 8. Synthesis and research directions

Viewed across these lines of work, projected Hamming distance is best understood as a unifying perspective on how Hamming geometry can be reconfigured by representation. In number-theoretic settings, projection isolates digit positions and reveals exact carry-driven structure [1203.4547]. In deep hashing, projection learns a binary latent space whose Hamming neighborhoods are semantically aligned with similarity targets [1810.01008]. In recommender systems, projection implements binary importance coding by disabling query-irrelevant bits while retaining Hamming-space efficiency [2103.14455]. In algorithms and data structures, projection compresses Hamming spaces into sketches that preserve enough distance information for approximate all-pairs computation, streaming, clustering, or sublinear matrix comparison [2504.14723], [1602.07241], [2107.02666].

These formulations suggest several stable conceptual axes. One axis is exact versus approximate projection: base-\(n\) and masked-code formulations are exact, whereas sketching and streaming formulations are approximate. A second axis is symmetric versus asymmetric distance: standard and learned projected Hamming distances are symmetric, while query-masked projected Hamming dissimilarity is not [2103.14455]. A third axis is static versus learned projection: coordinate decomposition and random sketches are fixed by construction, whereas learned hash codes adapt the projection to data and supervision [1810.01008].

A plausible implication is that “projected Hamming distance” functions less as a single canonical metric than as a design pattern: project first, compare in Hamming space second. The details of the projection determine whether the resulting object serves as an exact coordinate analysis, a learned retrieval metric, a query-conditioned dissimilarity, or a compressed approximation to a larger Hamming geometry.

Source: https://www.emergentmind.com/topics/projected-hamming-distance