Skip to content
Current section
The Quantum Computing Enthusiast’s Hub
Saved
All sections

All sections

Saved
Skip Learn navigation
Encyclopedia
Topic

Reversible comparison circuits

Coherent circuits that mark the ordering relation between binary integers while preserving their inputs.

Edition released Coverage: Overview · Technical
On this page

Definition, purpose and input assumptions

A reversible comparator computes a predicate such as a<b into a target bit, preserving a and b. It can mark good candidates for search or constrain arithmetic without destroying coherence. The bit width, signedness and overflow convention are essential parts of the predicate.

Mathematical mechanism

The ideal map is |a>|b>|t> -> |a>|b>|t XOR [a<b]>. It is its own inverse if inputs are unchanged. A construction can use subtraction and a borrow flag, but all temporary carries or borrows must be cleaned. Signed two's-complement comparison differs from unsigned comparison on the same bit patterns.

Fully solved reference example

Use two-bit unsigned numbers a=3 and b=1, represented as 11 and 01. The predicate a<b is false, so a zero target stays zero. Interpreting those same strings as two's-complement values gives a=-1 and b=1, making the predicate true. This is a semantic difference, not a circuit error.

For a coherent input (|a=0>+|a=2>)/sqrt(2), fixed b=1 and zero target, comparison yields (|0>|1>+|2>|0>)/sqrt(2) in a,target notation. Applying Z to the target and uncomputing gives (-|0>+|2>)/sqrt(2) with the target restored. Thus the comparator becomes a phase oracle for values below the threshold.

Limitations and classical comparison

A high-level comparison symbol hides arithmetic cost and ancillas. A classical comparator is usually much cheaper than its fault-tolerant reversible embedding, so quantum minimum-finding complexity must include predicate evaluation. Comparing approximate fixed-point values also requires a tie and precision policy.

Scientific relationships

Comparators are used in quantum minimum finding, reversible arithmetic and search oracles. They are distinct from measuring a value and choosing a classical branch.

An exact three-bit threshold predicate

For an unsigned three-bit input x=4a+2b+c, consider the strict predicate p=[x<5]. It is true on 000,001,010,011,100 and false on 101,110,111. The Boolean expression p=1 XOR a(b OR c) makes the threshold structure explicit: every input with a=0 is accepted, while a=1 is accepted only if both remaining bits vanish. Since b OR c=b XOR c XOR bc, the predicate has a direct reversible construction using a temporary bit.

Let workspace u start at zero and let the output flag z have an arbitrary initial value. Compute u=b OR c with CNOT b→u, CNOT c→u, and Toffoli b,c→u. Then apply X to z and Toffoli a,u→z. Finally reverse the workspace computation: Toffoli b,c→u, CNOT c→u, CNOT b→u. The output is z XOR p, and u is restored to zero. The complete construction uses three Toffoli gates, four CNOTs, and one X, on three input wires plus workspace and flag.

For input 100, u remains zero, so X changes the flag and the controlled update does nothing. For input 101, u becomes one; X and the controlled update cancel. For 110 and 111 the same cancellation occurs, including the OR computation on 11, where 1 XOR 1 XOR 1=1. For the four inputs with a=0, only X affects the flag. This verifies all eight cases through their logical branches, including the overlap term that would be lost by replacing OR with XOR.

Coherent marking and the role of cleanup

On a uniform superposition of the eight inputs and a zero flag, the probability of flag one is 5/8. The joint state groups five accepted labels with flag one and three rejected labels with flag zero. Discarding the flag removes coherence between these two groups. It is therefore not equivalent to preserving the original superposition and merely possessing a classical count of accepted labels.

With the flag initialized to |->, XOR by p instead produces phase (-1)^p on the input and leaves the flag in |->. The same workspace computation and reversal return u to zero. For example, input (|100>+|101>)/√2 becomes (-|100>+|101>)/√2. The relative sign is the useful output for amplitude amplification, while the input values themselves remain available for later verification or arithmetic.

Expanding the Boolean polynomial gives p=1 XOR ab XOR ac XOR abc. Consequently the phase oracle is -CZ(a,b) CZ(a,c) CCZ(a,b,c), with the leading minus sign denoting a scalar phase on the whole input space. This is a separate diagonal construction of the same marking operation. If the entire oracle is later controlled, that scalar becomes a conditional phase and must be retained. The equality follows from the integer parity of the four Boolean terms, not from replacing a reversible comparator by an ordinary classical branch.

Signed values, thresholds, and finite precision

The same three-bit strings represent -4,-3,-2,-1 on 100,101,110,111 in two's-complement arithmetic. The signed predicate x<1 accepts 000 and all four of those negative strings. The unsigned predicate x<1 accepts only 000. A circuit specification must therefore attach a numeric interpretation to its wires; the bit width alone is insufficient. Extending a signed integer to more bits also requires sign extension, whereas unsigned extension inserts leading zeros.

For approximate fixed-point values x~ and t~, suppose their errors relative to x and t are bounded by δ each. The computed difference differs from x-t by at most 2δ. Hence the ordering is guaranteed only when |x-t|>2δ. Within that interval, a tie policy or additional precision is required. Strict and non-strict comparisons disagree exactly at equality even in exact arithmetic, so replacing < by ≤ can change which states an oracle marks.

In minimum finding, a threshold may be updated after a measured candidate is verified classically. Each new threshold defines a new predicate circuit or new classical parameters for an arithmetic circuit. The query count for the abstract minimum-finding algorithm counts predicate access, while the total runtime also includes loading or evaluating candidate values, coherent comparison, cleanup, and final verification. A classical scan evaluates each value once and maintains the current minimum; it provides a concrete baseline when the values are already stored classically and coherent lookup is costly.

Generalization and an original truth-table figure

For longer integers, subtraction-based comparison can propagate a borrow or carry through the bit positions. Temporary arithmetic information must be uncomputed if the comparator is to serve repeatedly inside a coherent algorithm. A constant threshold, as in the example, can permit Boolean simplification that is unavailable when both operands are quantum registers. Thus the compact three-bit circuit should not be extrapolated into a constant-cost comparator for arbitrary precision.

Sources

  • Steven A. Cuccaro; Thomas G. Draper; Samuel A. Kutin; David Petrie Moulton · · Research paper · Publication status unspecified · arXiv
    Verification scope

    Recorded source check ·

    The version date comes from the arXiv submission record.

    Theoretical or mathematical source anchor; original definitions and worked instances are independent. No experimental or end-to-end performance claim inferred.

  • Christoph Durr; Peter Hoyer · · Research paper · Preprint recorded · arXiv
    Verification scope

    Selected source text checked ·

    Full text indexed, 2 pages, 248 lines. Primary minimum-finding paper retrieved; threshold pivot, finite stopping budget and probability guarantee inspected.

    Access and topic assumptions inspected; no exhaustive theorem-by-theorem external review, quantum hardware execution, or empirical advantage claim. Original definitions and finite examples are not reproduced source passages.