Comparator composition 2026-10-25
To combine more and less significant digital comparators, compute and use the displayed formulas. Unequal upper blocks decide the order, because their difference outweighs every possible lower-block difference; equal upper blocks delegate the decision to the lower block. This is an associative operation on the three comparison outcomes. A balanced binary tree of these combinations has circuit size and circuit depth for -bit inputs.
For bits , use two negation logic gates and two AND gates:
The two unequal bit pairs activate their respective output; the equal pairs activate neither. In particular, a digital comparator never produces .
Split each input into its more and less significant -bit halves: and . Let the two digital comparators produce and . The more significant halves are equal exactly when . The comparator composition is therefore
Implement with a logical disjunction followed by a negation, then use two AND gates and two more logical disjunction logic gates. If , the difference has magnitude at least , whereas ; hence the more significant comparison decides the result. If , the lower comparison decides it. This proves correctness in every case using a constant number of extra logic gates.
Apply comparator composition recursively in a balanced binary tree, with one-bit digital comparators at its leaves. For a power of two , the circuit size and circuit depth satisfy
There are leaves and internal nodes, so the circuit size is and the combinational delay is . Here each fixed-fan-in logic gate has bounded delay. For arbitrary , pad both inputs with leading zero bits to the next power of two, which is less than ; this preserves their unsigned interpretation and both bounds.