---
title: Dirty-Qubit Borrowing
url: https://www.emergentmind.com/topics/dirty-qubit-borrowing
type: topic
---

# Dirty-Qubit Borrowing

Dirty-qubit borrowing is the temporary use of ancillary qubits whose initial state is unknown and may be entangled, under the requirement that the computation be independent of those initial states and that the borrowed qubits be returned exactly to their original state. In the circuit literature, dirty ancillae or borrowed qubits are extra qubits in an unknown state that must be restored before the circuit ends; in the programming-languages literature, the same idea is formalized as safe uncomputation, with the overall effect required to be the identity on the borrowed subsystem. The technique is motivated by the scarcity of fresh clean qubits and by the observation that large quantum algorithms often contain qubits that encode coherent quantum information but remain idle for parts of the computation [1812.00954] [2508.17190] [1706.07884].

## 1. Definition and core criterion

A clean ancilla is an extra qubit initialized in a known state, typically \(|0\rangle\). A dirty qubit, or dirty ancilla, is an extra qubit whose initial state is unknown and possibly entangled with other parts of the computation, but which can be used temporarily provided the subroutine returns it exactly to its original state. A standard formal pattern is
\[
U:\ |\text{data}\rangle \otimes |\phi\rangle \mapsto |\text{data}'\rangle \otimes |\phi\rangle,
\]
for all unknown states \(|\phi\rangle\) on the borrowed qubits; this is the operational meaning of dirty-qubit borrowing in circuit synthesis and state preparation [1812.00954].

The programming-languages formulation makes the same requirement semantic. For a program \(S\) and a qubit \(q\), safe uncomputation means that for all \(E \in \llbracket S \rrbracket\),
\[
E = I_q \otimes E'
\]
for some quantum operation \(E'\) on the remaining qubits. In this form, dirty-qubit borrowing is not merely a resource heuristic but a program property: every possible execution must act as the identity on the borrowed qubit. The same paper proves equivalent state-restoration and entanglement-preservation statements, including preservation of any external entanglement involving the borrowed qubit [2508.17190].

This definition separates dirty-qubit borrowing from ordinary ancilla allocation. A clean ancilla may be overwritten and later reset to \(|0\rangle\); a dirty ancilla must be restored to whatever state it had originally, including any correlations that existed before the borrowing scope began. That stronger condition is what allows idle qubits to be reused safely.

## 2. Reversible arithmetic and Shor-era constructions

A major circuit-level development was the use of dirty ancillae in reversible arithmetic for factoring. “Factoring with \(n+2\) clean qubits and \(n-1\) dirty qubits” gives reversible classical circuits for arithmetic operations aided by dirty ancillae and improves the number of clean qubits needed to factor an \(n\)-bit number with Shor’s algorithm from \(1.5n+O(1)\) to \(n+2\), assisted by \(n-1\) dirty qubits, without increasing the asymptotic size or depth of the circuit [1706.07884].

In that construction, dirty bits are any temporarily unused wires. The central constraint is that they may start in an arbitrary, unknown state and must be restored exactly. The arithmetic toolkit includes addition, offset, comparison, increment, pivot-flips, modular addition, modular negation, modular doubling, modular scaled-addition, and modular bimultiplication. The period-finding construction uses \(2n+1\) total qubits: a single repeatedly reused phase-estimation qubit, an \(n\)-qubit work register, and an \(n\)-qubit ancilla register whose most significant bit is clean and fixed to \(|0\rangle\), while the remaining \(n-1\) qubits are dirty [1706.07884].

A characteristic primitive is modular bimultiplication. Instead of treating an ancilla register as disposable workspace, the circuit updates two registers symmetrically, multiplying one by \(K\) and the other by \(K^{-1}\) modulo \(R\). The ancilla register may therefore be dirty at the start, and a final clean-up multiplication restores it to its original value. This construction is the main mechanism by which dirty ancillae reduce the clean-qubit requirement in period finding [1706.07884].

The broader significance is methodological. Dirty-qubit borrowing in these reversible circuits is not an isolated trick but a design discipline: use reversible subroutines, ensure local uncomputation, and arrange the global algorithm so that any net action on the borrowed workspace can be canceled exactly. The resulting asymptotic costs remain \(O(n^3 \log n)\) gates and \(O(n^3)\) depth for the factoring construction, while the clean-qubit requirement is reduced to \(n+2\) [1706.07884].

## 3. Space–T tradeoffs in state preparation and synthesis

Dirty-qubit borrowing also became a systematic resource tradeoff in fault-tolerant synthesis. “Trading T gates for dirty qubits in state preparation and unitary synthesis” studies arbitrary state preparation and unitary synthesis in Clifford+T, with the explicit goal of borrowing idle qubits as dirty ancillas to reduce T-count [1812.00954].

The central mechanism is a T-efficient data-lookup oracle implemented by the SelectSwap network. For a \(b\)-bit oracle output and tunable parameter \(\lambda\), the SelectSwap construction has
\[
\text{Qubits}: \ b\lambda + 2\lceil \log_2 N \rceil,\qquad
\text{T-count}: \ 4\Big\lceil \frac{N}{\lambda} \Big\rceil + 8b\lambda,\qquad
\text{T-depth}: \ \frac{N}{\lambda} + \log \lambda.
\]
In the modified version, only
\[
b + 2\lceil \log_2 N \rceil
\]
qubits must be clean; the remaining \(b\lambda\) qubits can be dirty. The borrowed registers are entangled with the data during the computation and then disentangled and returned to their original state, which is exactly the operational meaning of dirty-qubit borrowing [1812.00954].

For state preparation of an arbitrary \(N\)-dimensional pure state specified by classical data, the paper uses \(O(\log(N/\epsilon))\) clean qubits and
\[
O\!\left(\lambda \log \frac{\log N}{\epsilon}\right)
\]
dirty qubits, with T-count
\[
O\!\left(
\frac{N}{\lambda}
+
\lambda \log\frac{N}{\epsilon}\,\log\frac{\log N}{\epsilon}
\right).
\]
For unitary synthesis of \(K\) specified columns, the corresponding bound is
\[
O\!\left(
K\left(
\frac{N}{\lambda}
+
\lambda \log\frac{N}{\epsilon}\,\log\frac{K\log N}{\epsilon}
\right)
\right).
\]
The paper proves lower bounds showing that these space–T tradeoffs are optimal up to logarithmic factors, and in the best case yield a quadratic improvement in T-count over prior ancillary-free approaches [1812.00954].

In this line of work, dirty-qubit borrowing is not tied to a particular arithmetic family. It becomes a generic compiler-level principle: almost all ancillas used for data lookup and amplitude-loading machinery can be dirty, while only \(O(\log(N/\epsilon))\) qubits must be clean [1812.00954].

## 4. Language semantics and formal verification

A later development was to lift dirty-qubit borrowing from circuit folklore to language semantics. “Borrowing Dirty Qubits in Quantum Programs” introduces a \textsf{QBorrow} language with an explicit borrowing construct
```text
borrow a; S; release a
```
and defines its denotation by ranging over all qubits in \(idle(S)\), the set of qubits syntactically unused by \(S\). Formally,
\[
\llbracket borrow\ a;S;release\ a \rrbracket
=
\bigcup_{q\in idle(S)} \llbracket S[q/a]\rrbracket.
\]
Borrowing is therefore nondeterministic at the semantic level: any idle physical qubit may instantiate the placeholder \(a\) [2508.17190].

The same paper defines safe uncomputation exactly as identity action on the borrowed subsystem and proves two particularly important equivalents. First, for every global state and every one-qubit pure state \(|\psi\rangle\), if the reduced state of \(q\) is \(|\psi\rangle\langle\psi|\) initially, then it remains \(|\psi\rangle\langle\psi|\) after every execution. Second, the borrowed qubit’s entanglement with any external auxiliary system is preserved exactly. These equivalences make the operational meaning of safe borrowing precise: the borrowed qubit is invisible to the rest of the program except as temporary workspace whose full state is restored [2508.17190].

For classical circuits composed only of \(X\) and multi-controlled NOT gates, the paper gives an efficient verification reduction. A dirty qubit \(q\) is safely uncomputed if restoration holds for \(|0\rangle\) and \(|+\rangle\), and the check reduces to the unsatisfiability of two Boolean formulas, one testing preservation of \(q=0\) and the other testing whether any other output depends on the initial value of \(q\). The implementation uses CVC5 and Bitwuzla and verifies adder circuits up to 200 qubits and MCX circuits up to 3499 qubits [2508.17190].

This formalization resolves a long-standing ambiguity in the phrase “borrow a dirty qubit.” In circuit design, the phrase often meant that a construction was believed to restore its borrowed workspace. In the semantics of \textsf{QBorrow}, that belief becomes a theorem or a failed proof obligation.

## 5. Recycling, reset, and experimental ancilla reuse

Dirty-qubit borrowing is closely related to, but not identical with, broader qubit-reuse mechanisms. “Recycling qubits in near-term quantum computers” proposes a rewinding protocol that unitarily resets qubits when a circuit has a common convolutional form. The protocol generates fresh qubits from used ones by partially applying the time-reversed quantum circuit over qubits that are no longer in use, and in the absence of noise the state of a subset of these qubits becomes \(|0\ldots 0\rangle\), up to an error exponentially small in the number of gates applied. The paper also provides numerical evidence that the protocol works in the presence of noise and formulates a condition under which the noise-resilience follows rigorously [2012.01676].

This protocol is not dirty-qubit borrowing in the strict sense because the original unknown state of the qubit is not preserved; instead, the used qubit is approximately reset to a fresh ancilla state. Even so, it belongs to the same resource family: qubits are reused rather than allocated anew, and the reuse is certified by structural properties of the circuit [2012.01676].

A platform-level realization of repeated ancilla reuse appears in neutral atoms. “Repeated ancilla reuse for logical computation on a neutral atom quantum computer” demonstrates the ability to measure and re-initialize, and if necessary replace, a subset of atoms while maintaining coherence in other atoms. The system performs logical circuits that include single- and two-qubit gates as well as repeated midcircuit measurement, highlights the capability by performing up to 41 rounds of syndrome extraction in a repetition code, and combines midcircuit measurement and atom replacement with real-time conditional branching to demonstrate heralded state preparation of a logically encoded Bell state. The measured impact on register qubits per MCM cycle is an atom loss of \(0.0106(7)\) and a Ramsey contrast loss among surviving atoms of \(0.0049(7)\) [2506.09936].

This suggests a broader operational family of qubit reuse mechanisms. Strict dirty-qubit borrowing restores an unknown initial state; recycling and midcircuit reset restore a known fresh state. Both reduce pressure on scarce clean ancillas, but they solve different resource problems and make different semantic promises.

## 6. Related uses of “dirty” qubits and scope of the term

The phrase “dirty qubit” is not uniform across quantum information. In “The battle of clean and dirty qubits in the era of partial error correction,” a clean-and-dirty setup partitions an \(n\)-qubit device into \(n_c\) clean qubits and \(n_d\) dirty qubits, where clean qubits evolve unitarily and dirty qubits are followed by a noise channel. In that setting, dirty qubits are uncorrected noisy qubits, not borrowed ancillas that must be restored. The paper shows the appearance of Noise-Induced Barren Plateaus in an Ising-model Hamiltonian variational ansatz, observes this even if only a single qubit is noisy and given a deep enough circuit, and finds that for every noiseless qubit in the circuit there is an exponential suppression in concentration of gradient observables, with the exponent related to the ratio of dirty-to-total qubits [2205.13454].

A second neighboring usage appears in noisy-storage cryptography. “Cryptography from Noisy Storage” models qubits stored by an adversary as noisy resources and proves that a protocol for oblivious transfer is secure for any amount of quantum-storage noise, as long as honest players can perform perfect quantum operations. There, “dirty” refers to decohered storage rather than to a borrowable ancilla whose state must be restored [0711.2895].

A third neighboring usage concerns physical carriers. “Qubit carriers with internal degrees of freedom in a non-factorable state” studies particles that carry logical qubits while hidden internal degrees of freedom are non-factorable. The key parameter is
\[
D=\operatorname{Tr}[F\rho_{E,ST}],
\]
and the transferred state becomes
\[
\rho_T=\frac{1+D}{2}|\Psi_S\rangle\langle\Psi_S|+\frac{1-D}{2}|\Psi_S^\perp\rangle\langle\Psi_S^\perp|.
\]
Here the relevant issue is distinguishability and dephasing of the carrier, not safe borrowing of an idle computational qubit [1209.0908].

These distinctions matter because they mark different notions of “dirtiness.” In the borrowing literature, dirtiness means unknown initial state plus exact restoration. In partial error correction, it means exposure to noise. In noisy storage, it means decoherence as a cryptographic assumption. In carrier models, it means inaccessible internal degrees of freedom. Conflating these notions obscures the central invariant of dirty-qubit borrowing: the borrowed subsystem must be returned exactly, including any entanglement it carried at the moment of borrowing.

Source: https://www.emergentmind.com/topics/dirty-qubit-borrowing