# Commutation rules between Pauli $X$ and controlled-Hadamard

Are there any known commutation rules between the $$X$$ gate and the $$CH$$ gate?

There are two cases: $$X$$ on the controlled qubit and $$X$$ on the target.

## $$X$$ on the controlled qubit

For the first case, note that for any controlled unitary $$CU$$, we have

$$(X_1\otimes I_2)\circ C_1U_2 = C_1U_2^\dagger\circ (X_1\otimes U_2)\tag1$$

which is easy to prove by separately considering the action of both sides on $$|0\rangle|\psi\rangle$$ and $$|1\rangle|\psi\rangle$$.

## $$X$$ on the target qubit

For the second case, we can use $$XH=HZ$$ to write

\begin{align} (I_1\otimes X_2)\circ C_1H_2 &= \begin{bmatrix}X&\\& X\end{bmatrix} \begin{bmatrix}I&\\& H\end{bmatrix}\\ &= \begin{bmatrix}X&\\& XH\end{bmatrix}\\ &= \begin{bmatrix}X&\\& HZ\end{bmatrix}\\ &= \begin{bmatrix}I&\\& H\end{bmatrix} \begin{bmatrix}X&\\& I\end{bmatrix} \begin{bmatrix}I&\\& Z\end{bmatrix}\\ &= C_1H_2\circ\begin{bmatrix}X&\\& I\end{bmatrix}\circ C_1Z_2 \end{align}\tag2

where the matrix $$\mathrm{diag}(X, I)$$ represents the quantum gate that flips the second qubit if the first qubit is in the $$|0\rangle$$ state. We can synthesize this gate as

\begin{align} \begin{bmatrix}X&\\& I\end{bmatrix} &= \begin{bmatrix}&I\\I&\end{bmatrix} \begin{bmatrix}I&\\& X\end{bmatrix} \begin{bmatrix}&I\\I&\end{bmatrix}\\ &= (X_1\otimes I_2)\circ C_1X_2\circ(X_1\otimes I_2). \end{align}\tag3

Substituting $$(3)$$ into $$(2)$$, we end up with

$$(I_1\otimes X_2)\circ C_1H_2 = C_1H_2\circ(X_1\otimes I_2)\circ C_1X_2\circ(X_1\otimes I_2)\circ C_1Z_2.\tag4$$

## Reducing the number of controlled gates

The technique above allows us to reduce the number of resulting controlled gates by exploiting identities such as $$XZ=-iY$$

\begin{align} (I_1\otimes X_2)\circ C_1H_2 &= \begin{bmatrix}X&\\& X\end{bmatrix} \begin{bmatrix}I&\\& H\end{bmatrix}\\ &= \begin{bmatrix}X&\\& XH\end{bmatrix}\\ &= \begin{bmatrix}X&\\& HZ\end{bmatrix}\\ &= \begin{bmatrix}I&\\& H\end{bmatrix} \begin{bmatrix}X&\\& Z\end{bmatrix}\\ &= C_1H_2\circ\begin{bmatrix}X&\\& X\end{bmatrix} \begin{bmatrix}I&\\& XZ\end{bmatrix}\\ &= C_1H_2\circ(I_1\otimes X_2)\circ\begin{bmatrix}I&\\& -iY\end{bmatrix}\\ &= C_1H_2\circ(I_1\otimes X_2)\circ S_1^\dagger \circ C_1Y_2 \end{align}\tag5

which agrees with the identity obtained by Craig Gidney using quirk.

With a few minutes in Quirk you can confirm that

$$X_c \cdot \text{CH}_{c \rightarrow t} = \text{CH}_{c \rightarrow t} \cdot X_c H_t$$

and

$$X_t \cdot \text{CH}_{c \rightarrow t} = \text{CH}_{c \rightarrow t} \cdot X_t \text{CY}_{c \rightarrow t} S^\dagger_c$$