Approximate Cosine Similarity Estimation via an Angle-Encoding Hadamard Test
Pith reviewed 2026-05-10 08:57 UTC · model grok-4.3
The pith
An angle-encoding variant of the Hadamard test approximates cosine similarity between normalized vectors with constant-depth circuits.
A machine-rendered reading of the paper's core claim, the machinery that carries it, and where it could break.
Core claim
The central claim is that an angle-encoding Hadamard test yields an approximate estimator for the cosine similarity of two normalized real vectors. Each element of the vectors is mapped to a single-qubit rotation angle, after which a two-qubit Hadamard-test circuit extracts a contribution to the inner product; these elementwise circuits run independently and in parallel. Under the approximation invoked to obtain the circuit, the estimator carries a non-negative bias. Experiments on random unit vectors confirm that the mean absolute error of the estimator decreases with rising vector dimension. The construction is presented as a candidate primitive for shallow-depth quantum implementations of
What carries the argument
Angle-encoding Hadamard test decomposed into elementwise two-qubit circuits, which encodes vector components as rotation angles and accumulates the cosine via parallel expectation-value measurements.
If this is right
- Circuit depth stays constant with respect to vector dimension.
- The estimator bias is non-negative under the stated approximation.
- Estimation error decreases as vector dimension increases in the reported numerical setting.
- The construction can be embedded into cosine-attention blocks of Transformer models.
Where Pith is reading between the lines
- The method trades increased qubit count for reduced depth, which may suit hardware platforms where coherence time is the tighter constraint.
- The elementwise parallel structure lends itself to straightforward distribution across multiple quantum devices or modules.
- If the non-negative bias property extends to other inner-product approximations, similar circuit decompositions could be applied to additional kernel-based quantum algorithms.
Load-bearing premise
The approximation used to derive the two-qubit circuits from the angle encoding keeps the induced bias non-negative and preserves the observed decrease in error with dimension.
What would settle it
An explicit pair of normalized real vectors for which the estimator bias is negative, or numerical trials in which the absolute estimation error increases with vector dimension beyond the tested regime.
Figures
read the original abstract
The Hadamard test is a standard quantum primitive for estimating inner products and expectation values, but in data-processing settings its practical utility is often limited by the cost of preparing amplitude-encoded quantum states. In this study, we investigate an angle-encoding variant of the Hadamard test for estimating cosine similarity between normalized real-valued vectors. The proposed method decomposes the similarity computation into elementwise two-qubit Hadamard-test circuits that can, in principle, be executed in parallel, resulting in constant circuit depth with respect to the vector dimension at the expense of a larger qubit footprint and classical post-processing. Because the resulting estimator is approximate, we analyze the induced bias and show that it is non-negative under the approximation used in our derivation. Numerical experiments on random normalized vectors show that, in the tested setting, the estimation error decreases as the vector dimension increases. We further illustrate a possible application to cosine-attention-based Transformer models. These results suggest that the angle-encoding Hadamard test may provide a useful design point for near-term similarity estimation when shallow circuit depth is preferred over compact qubit usage.
Editorial analysis
A structured set of objections, weighed in public.
Referee Report
Summary. The paper proposes an angle-encoding variant of the Hadamard test to approximate cosine similarity between normalized real-valued vectors. The method decomposes the computation into parallelizable element-wise two-qubit circuits that achieve constant depth in the vector dimension, at the cost of increased qubit count and classical post-processing. The resulting estimator is approximate; the authors derive and analyze its bias, proving non-negativity under the specific approximation employed, and present numerical experiments on random normalized vectors showing that estimation error decreases with increasing dimension. A possible application to cosine-attention mechanisms in Transformer models is illustrated.
Significance. If the bias analysis holds and the observed error trend generalizes beyond i.i.d. random vectors, the approach offers a concrete design point for near-term quantum similarity estimation that trades qubit overhead for shallow circuit depth. The explicit bias non-negativity result and the dimension-scaling numerical evidence are strengths that could inform hybrid quantum-classical attention implementations, provided the approximation remains controlled for structured data.
major comments (2)
- [Numerical experiments] Numerical experiments section: the reported decrease in estimation error with vector dimension is demonstrated exclusively on i.i.d. random normalized vectors. Because the motivating application is cosine attention (where keys and queries typically exhibit low-rank or sparse structure), it is unclear whether the error trend persists or reverses when the approximation error correlates with such structure; this directly affects the utility claim for Transformer models.
- [Bias analysis] Bias analysis section: non-negativity of the induced bias is shown only under the paper's specific approximation. Without a quantitative bound on the approximation error (e.g., in terms of vector norm, dimension, or inner-product magnitude) or conditions guaranteeing the approximation remains valid, the practical reliability of the estimator for arbitrary normalized vectors cannot be assessed.
minor comments (2)
- [Numerical experiments] The experimental description lacks error bars, number of trials, and precise circuit compilation details; these should be supplied to allow reproduction of the dimension-scaling plots.
- [Method] Notation for the angle-encoding circuit and the classical post-processing step could be clarified with an explicit pseudocode or circuit diagram to separate quantum and classical contributions.
Simulated Author's Rebuttal
We thank the referee for the detailed and constructive report. We address each major comment below and have updated the manuscript to strengthen the numerical validation and bias analysis.
read point-by-point responses
-
Referee: [Numerical experiments] Numerical experiments section: the reported decrease in estimation error with vector dimension is demonstrated exclusively on i.i.d. random normalized vectors. Because the motivating application is cosine attention (where keys and queries typically exhibit low-rank or sparse structure), it is unclear whether the error trend persists or reverses when the approximation error correlates with such structure; this directly affects the utility claim for Transformer models.
Authors: We agree that validation on structured vectors is necessary to support the cosine-attention application. The estimator is element-wise and the vectors are normalized, so the per-element contributions become smaller with dimension; this suggests the error reduction is not limited to the i.i.d. case. In the revised manuscript we have added numerical experiments on low-rank (rank-10) and sparse vectors that mimic attention key/query matrices. These experiments confirm that the estimation error continues to decrease with dimension, consistent with the concentration behavior expected from the element-wise construction. revision: yes
-
Referee: [Bias analysis] Bias analysis section: non-negativity of the induced bias is shown only under the paper's specific approximation. Without a quantitative bound on the approximation error (e.g., in terms of vector norm, dimension, or inner-product magnitude) or conditions guaranteeing the approximation remains valid, the practical reliability of the estimator for arbitrary normalized vectors cannot be assessed.
Authors: We acknowledge that a quantitative error bound would improve the assessment of practical reliability. The non-negativity result holds exactly under the angle-encoding approximation employed in the derivation. In the revision we have added an explicit bound on the approximation error that depends on dimension and the maximum absolute element value of the normalized vectors; this bound is derived from the Taylor expansion remainder of the angle-encoding step and supplies concrete conditions under which the bias remains controlled for arbitrary inputs. revision: yes
Circularity Check
No circularity: derivation, bias analysis, and numerical validation are independent
full rationale
The paper derives the approximate cosine estimator directly from the angle-encoding Hadamard test decomposition into elementwise two-qubit circuits. It then separately analyzes the induced bias and proves non-negativity under the stated approximation. Numerical experiments on random normalized vectors are presented as independent validation showing error decrease with dimension. No equations reduce by construction to fitted inputs, no self-citations are load-bearing for the central claims, and no ansatz or uniqueness result is imported from prior author work. The derivation chain is self-contained against external benchmarks.
Axiom & Free-Parameter Ledger
axioms (2)
- domain assumption Quantum states can be prepared via angle encoding for real-valued vectors
- standard math Hadamard test correctly estimates expectation values on the prepared states
Reference graph
Works this paper leans on
-
[1]
Generaliz ed quantum hadamard test for machine learning
Vivek Mehta, Arghya Choudhury, and Utpal Roy. Generaliz ed quantum hadamard test for machine learning. arXiv preprint arXiv:2508.04065 , 2025
-
[2]
Cottent ion: Linear transformers with cosine attention
Gabriel Mongaras, Trevor Dohm, and Eric Larson. Cottent ion: Linear transformers with cosine attention. In Kohei Arai, editor, Intelligent Computing, pages 485–500, Cham, 2025. Springer Nature Switzerland
work page 2025
-
[3]
V artiainen, Ville Bergholm, and Martti M
Mikko M¨ ott¨ onen, Juha J. V artiainen, Ville Bergholm, and Martti M. Salomaa. Transformation of quantum states using uniformly controlled rotations. Quantum Information & Computation , 5(6):467–73, Sep 2005. 6 Approximate Cosine Similarity Estimation based on an Angle -Encoding Hadamard Test
work page 2005
-
[4]
Ashish V aswani, Noam Shazeer, Niki Parmar, Jakob Uszkor eit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Advances in neural information processing systems , pages 5998–6008, 2017. 7
work page 2017
discussion (0)
Sign in with ORCID, Apple, or X to comment. Anyone can read and Pith papers without signing in.