Controlled and daggered gates: decomposition reference¶
This guide is organised by the gate being modified. Each entry states the native cases, the controlled decomposition, and the dagger rule. The decompositions describe logical gates; subsequent compilation determines the hardware gate set.
Gate index¶
See also the worked examples for explicit circuits and restoration of dirty ancillas[1].
Notation and phase conventions¶
All rotation parameters are in half-turns:
For example, \(\theta=1/2\) means a rotation through \(\pi/2\) radians. Define the scalar phase \(\Phi(\alpha)=e^{i\pi\alpha}I\).
For a register of positive controls \(C=(c_1,\ldots,c_k)\),
The gate acts only when every control is \(1\). All identities hold for coherent controls, including superposition and entanglement. For an empty register, \(\Lambda_\varnothing(U)=U\).
Sequences are written in execution order, from left to right. Thus \(A\ ;\ B\) means apply \(A\) and then \(B\), with matrix \(BA\). Subscripts identify the target; \(\Lambda_c(U_t)\) has control \(c\) and target \(t\).
In entries for gates that already have controls, \(C\) denotes the additional controls; the formulas explicitly include the original controls.
Control and dagger commute:
A decomposed circuit is daggered by reversing execution order and taking the adjoint of each factor.
Unless marked \(\simeq\), the identities below are exact with scalar phases retained. The compiler removes remaining unconditional scalar phases after modifier resolution. Consequently, the final circuit is equivalent up to an overall global phase; conditional phases remain implemented on the controls.
X¶
Native cases. With one control, emit CX. With two controls, emit Toffoli. Larger control registers use one of the following recursive constructions.
With a dirty ancilla¶
Write the full control register as \((C_1,C_2,x,y)\). The two designated controls \(x,y\) form a Toffoli together with target \(t\). If there are \(k\) remaining controls, partition them with
For a borrowed dirty ancilla \(a\), define
Then
with identity action on \(a\) after the complete sequence. Each block is recursively decomposed until native cases are reached.
To see that the dirty ancilla is restored, let
An empty conjunction equals \(1\). The two \(A\) blocks change a basis value \(a_0\) to \(a_0\oplus p\) and back to \(a_0\). The two \(B\) blocks produce the net target toggle
There are no basis-dependent phases, so the identity also restores arbitrary superpositions and entanglement.
For example, a three-controlled X with controls \((x,y,c)\) uses
Without an available dirty ancilla¶
Split the full control register as \((D,c)\). Using the phase-normalised square root \(V^2=X\), the compiler uses
The selected control \(c\) is toggled and restored. If \(p=\bigwedge D\), the net target action is
The controlled V blocks use the V decomposition. Recursive subproblems can borrow \(t\) while modifying \(c\), or borrow the restored \(c\) for the final controlled V. These borrowed qubits are restored before the subproblem returns. Thus this construction needs no additional qubit for the enclosing gate, although recursive subproblems can use dirty-ancilla identities.
Dagger. \(X^\dagger=X\), and every multi-controlled X is self-adjoint.
CX¶
Let \(c\) be the original control and \(t\) the target. Adding controls \(C\) gives
With one additional control, emit native Toffoli. With two or more additional controls, use the multi-controlled X constructions with the original control included in the full control register.
Dagger. CX and all its controlled versions are self-adjoint.
Toffoli¶
Let \(x,y\) be the original controls and \(t\) the target. Adding controls \(C\) gives
With no additional controls, retain native Toffoli. With additional controls, use the multi-controlled X constructions. In the dirty-ancilla construction, retain \(x,y\) as the designated controls and partition the additional register \(C\) into \(C_1,C_2\).
Dagger. Toffoli and all its controlled versions are self-adjoint.
Y¶
One control. Emit native CY.
Two or more controls. Use
The S gates are unconditional. This follows from \(SXS^\dagger=Y\); in inactive control sectors, \(S^\dagger\) and S cancel. Resolve the central gate using the X entry.
Dagger. Y and every controlled Y are self-adjoint.
CY¶
For original control \(c\), target \(t\), and additional controls \(C\),
Retain native CY when there are no additional controls. Otherwise use the displayed identity and the X entry, including \(c\) among the central gate’s controls.
Dagger. CY and every controlled CY are self-adjoint.
Z¶
One control. Emit native CZ.
Two or more controls. Use
The H gates are unconditional. The identity follows from \(HXH=Z\), and the basis changes cancel in inactive control sectors. Resolve the central gate using the X entry.
Dagger. Z and every controlled Z are self-adjoint.
CZ¶
For original control \(c\), target \(t\), and additional controls \(C\),
Retain native CZ when there are no additional controls. Otherwise use the displayed identity and the X entry.
Dagger. CZ and every controlled CZ are self-adjoint.
H¶
For any nonempty control register,
Both factors carry the full control register. In the active sector, \(XR_y(1/2)=H\); in inactive sectors, both factors are identity. Resolve the factors using the Ry and X entries.
Dagger. H is self-adjoint. The adjoint decomposition is
which implements the same controlled H.
Rx¶
For any nonempty control register,
The H gates are unconditional. The identity follows from \(HZH=X\), and they cancel in inactive control sectors. Resolve the central gate using the Rz entry.
Dagger. Replace \(\theta\) by \(-\theta\).
Ry¶
For any nonempty control register,
The S gates are unconditional. This follows from \(SXS^\dagger=Y\). Resolve the central gate using the Rx entry.
Dagger. Replace \(\theta\) by \(-\theta\).
Rz¶
One control. Emit native CRz with the same parameter \(\theta\).
Two or more controls. Use the half-angle decomposition
Both rotations are unconditional; both X gates carry the full control register. Resolve the X blocks using the X entry.
In inactive control sectors, the rotations cancel. In the active sector, the target matrix is
using \(XR_z(\beta)X=R_z(-\beta)\).
The parameter can be evaluated at runtime: the decomposition requires only halving and negation.
Dagger. Replace \(\theta\) by \(-\theta\).
CRz¶
Let \(c\) be the original control and \(t\) the target. With additional controls \(C\),
Retain native CRz when there are no additional controls. Otherwise use
The original control \(c\) participates in both X blocks. Their decomposition is given in the X entry.
Dagger. Replace \(\theta\) by \(-\theta\).
S and Sdg¶
The exact gate identities are
For any nonempty control register,
Here \(P_C(\alpha)\) applies phase \(e^{i\pi\alpha}\) to the all-ones control state. It acts on the controls, independently of the target. Resolve it using the global-phase entry, and the rotation using Rz.
For one control, the exact decomposition is
The final scalar is removed after modifier resolution. The rotation on \(c\) remains essential to the controlled S operation.
Dagger. Exchange S and Sdg; both the rotation parameter and phase parameter change sign.
T and Tdg¶
The exact gate identities are
For any nonempty control register,
Resolve the conditional phase using the global-phase entry, and the rotation using Rz.
For one control, the exact decomposition is
Only the final unconditional scalar is removed after modifier resolution.
Dagger. Exchange T and Tdg; both the rotation parameter and phase parameter change sign.
V and Vdg¶
These decompositions use the phase-normalised square root of X:
For any nonempty control register,
Resolve the rotation using Rx, and the conditional phase using the global-phase entry.
For one control, this becomes
The phase correction is essential to the multi-controlled X construction. Substituting \(R_x(1/2)\) alone would give a square of \(-iX\), changing the operation in the active control sector.
Dagger. Exchange V and Vdg; both the rotation parameter and phase parameter change sign.
Global phase¶
Note
Global phase is not currently exposed in Guppy’s public API; support is planned for a future release. The compiler uses it internally for decompositions such as controlled S (CS), as shown in the S and Sdg entry.
A scalar phase becomes a conditional phase when controlled:
For nonempty \(C\), this gate multiplies the all-ones control state by \(e^{i\pi\alpha}\) and leaves every other basis state unchanged. There is no separate target qubit.
Split \(C=(D,c)\). The recursive decomposition is
When \(D\) is inactive, both factors are identity. When \(D\) is active,
The base case is \(P_\varnothing(\alpha)=\Phi(\alpha)\). For example,
For \(k\) controls, the recursion produces rotations with \(0,1,\ldots,k-1\) controls, with parameters
and a remaining scalar \(\Phi(\alpha/2^k)\). Resolve each controlled rotation using Rz. Only the remaining unconditional scalar is discarded after all controls have been resolved.
Dagger. Replace \(\alpha\) by \(-\alpha\).
Worked examples¶
The examples use the same left-to-right execution order and half-turn parameters as the reference entries.
Example 1: controlled T and Tdg¶
Consider T on target \(t\) with one control \(c\). Its decomposition is
The controlled rotation acts on \(t\); the phase-correction rotation acts on \(c\). The scalar \(\Phi(1/16)\) is removed after modifier resolution, giving the emitted logical circuit
The exact controlled T has matrix \(\operatorname{diag}(1,1,1,e^{i\pi/4})\) in the basis \(|ct\rangle\). The displayed circuit implements this matrix multiplied by the common scalar \(e^{-i\pi/16}\).
The daggered version changes both signs:
After removal of the scalar, the circuit is
In both cases, the rotation on the control is required to obtain the correct relative phase between control sectors.
Example 2: doubly controlled daggered Rx¶
Consider \(R_x(1/2)^\dagger\) on \(t\) with controls \(c_1,c_2\). First negate the parameter:
Change basis using H, and expand the doubly controlled Rz with half-angle rotations. The two controlled X blocks are native Toffolis:
Here \(\operatorname{Toffoli}(x,y;z)\) has controls \(x,y\) and target \(z\).
When either control is zero, the Toffolis are inactive, the Rz rotations cancel, and the H gates cancel. When both controls are one, the central sequence has matrix
Conjugating by H gives \(R_x(-1/2)\), as required. This example uses no borrowed ancilla and needs no phase correction.
Example 3: four-controlled X borrowing its target as a dirty ancilla¶
Consider \(\Lambda_{c_1,c_2,c_3,c_4}(X_t)\) with the controls ordered as \((c_1,c_2,c_3,c_4)\). The normal pass begins resolution of the original gate with an empty ancilla list. Its five-block decomposition is
The controlled V factors are subsequently resolved using the V entry. Within each highlighted X block, \(c_4\) is the target and the existing qubit \(t\) is temporarily available as a dirty ancilla.
Each highlighted block is implemented as
To track restoration, write \(p=c_2c_3\), \(q=c_1\), and let the initial basis values of \(t,c_4\) at entry to the block be \(a,b\):
Step |
Borrowed qubit \(t\) |
Subproblem target \(c_4\) |
|---|---|---|
Initially |
\(a\) |
\(b\) |
First Toffoli |
\(a\oplus p\) |
\(b\) |
Second Toffoli |
\(a\oplus p\) |
\(b\oplus q(a\oplus p)\) |
Third Toffoli |
\(a\) |
\(b\oplus q(a\oplus p)\) |
Fourth Toffoli |
\(a\) |
\(b\oplus pq\) |
Thus \(c_4\) flips exactly when \(c_1c_2c_3=1\), while \(t\) is restored exactly to its state at entry to the block.
The sequence introduces no basis-dependent phases, so restoration also holds for superpositions and entanglement. In particular, \(t\) may already be entangled with \(c_4\) by the preceding controlled V.
After the borrowed-qubit block returns, the enclosing decomposition continues to use \(t\) as its original target. No additional qubit is allocated: the dirty workspace is provided internally by recursive borrowing.