# Unitary operations in a Quantum Neural Network

I'm currently reading Classification with Quantum Neural Networks on Near Term Processors and I'm having trouble with one of the calculations.

The system is composed of $$n+1$$ qubits, $$n$$ of those are used as inputs and the last one as an output qubit. Given a label function $$l(z)$$ that returns +1 or -1 depending on the state $$|z\rangle$$, the unitary $$U_l$$ is defined as $$U_l|z,z_{n+1}\rangle = exp(i\frac{\pi}{4}l(z)X_{n+1})|z,z_{n+1}\rangle$$ It is mentionned in the paper that this operation is equivalent to rotating the output qubit about its x-axis by $$\frac{\pi}{4}$$ times the label of the string $$z$$. The next statement is the one that confuses me and I cannot derive it properly: $$U_l^\dagger Y_{n+1}U_l = cos(\frac{\pi}{2}l(Z))Y_{n+1} + sin(\frac{\pi}{2}l(Z))Z_{n+1}$$ where $$l(Z)$$ is interpreted as an operator diagonal in the computational basis.

I managed to derive a few lines but I'm having trouble matching the statement above, here is where I'm stuck: \begin{aligned} U_l^\dagger Y_{n+1}U_l &= U_l^\dagger [Y_{n+1},U_l] + U_l^\dagger U_l Y_{n+1}\\ &= U_l^\dagger [Y_{n+1},U_l] + Y_{n+1} \end{aligned} \begin{aligned}[] [Y_{n+1},U_l] &= [Y_{n+1}, \sum_{k=0}^\infty \frac{(i\frac{\pi}{4}l(z))^k}{k!}{X_{n+1}}^k]\\ &= \sum_{l=0}^{\infty}\frac{(-1)^l}{(2l)!}\left(\frac{\pi}{4}l(z)\right)^{2l}[Y_{n+1}, I_{n+1}] + i\sum_{m=0}^{\infty}\frac{(-1)^m}{(2m+1)!}\left(\frac{\pi}{4}l(z)\right)^{2m+1}[Y_{n+1}, X_{n+1}]\\ &= 0 + 2\sin(\frac{\pi}{4}l(z))Z_{n+1} \end{aligned} where we split the sum into even and odd terms. This gives in the end: \begin{aligned} U_l^\dagger Y_{n+1}U_l = Y_{n+1} + 2\sin(\frac{\pi}{4}l(z))Z_{n+1} \end{aligned} This is where I'm stuck. Did I make a mistake along the way?

• could the general relation $e^A B e^{-A}=\exp(\operatorname{ad}(A))B\equiv B+[A,B]+\frac12[A,[A,B]]+...$ help here?
– glS
Commented Oct 19, 2022 at 23:47
• Actually it does, I had not noticed that by choosing $A = -i\frac{\pi}{4}l(z)X_{n+1}$, we have $A^{\dagger} = -A$ and that satisfies the conditions of the Baker-Campbell-Hausdorf relation Commented Oct 20, 2022 at 15:11

Following the remark of @glS, we can reformulate the problem using the Baker-Campbell-Hausdorf formula and we manage to derive the right results. Here are some details for the calculations: \begin{aligned} U_l^{\dagger}Y_{n+1}U_l &= e^{A}Y_{n+1}e^{-A} \qquad\qquad\qquad\qquad,\quad A = -i\frac{\pi}{4}l(z)X_{n+1}\\ &= \sum_{k=0}^{\infty}\frac{[(A)^k,Y_{n+1}]}{k!}\\ &= Y_{n+1} + (-i\frac{\pi}{4}l(z))[X_{n+1},Y_{n+1}] + \frac{1}{2!}(i\frac{\pi}{4}l(z))^2[X_{n+1},[X_{n+1},Y_{n+1}]]+...\\ &= Y_{n+1} + (-i\frac{\pi}{4}l(z))(2iZ_{n+1})+\frac{1}{2!}(i\frac{\pi}{4}l(z))^2(-(2i)^2Y_{n+1})+...\\ &= \sum_{k=0}^{\infty}\frac{(-i\frac{\pi}{4}l(z))^{2k}(2i)^{2k}(-1)^k}{(2k)!}Y_{n+1} + \sum_{k=0}^{\infty}\frac{(-i\frac{\pi}{4}l(z))^{2k+1}(2i)^{2k+1}(-1)^k}{(2k+1)!}Z_{n+1}\\ &= \cos(\frac{\pi}{2}l(z))Y_{n+1}+\sin(\frac{\pi}{2}l(z))Z_{n+1} \end{aligned} where we used the Pauli matrices commutation relations to simplify the sum of commutators, i.e. $$[X,Y]=2iZ$$ and $$[X,Z]=-2iY$$.
Another approach that was also successful is to compute the matrix product $$U_l^{\dagger}Y_{n+1}U_l$$ by writing $$U_l$$ explicitly: \begin{aligned} U_l = e^{i\frac{\pi}{4}l(z)X_{n+1}} &= \sum_{k=0}^{\infty}\frac{(i\frac{\pi}{4}l(z))^{2k}}{(2k)!}(X_{n+1})^{2k} + \sum_{k=0}^{\infty}\frac{(i\frac{\pi}{4}l(z))^{2k+1}}{(2k+1)!}(X_{n+1})^{2k+1}\\ &= \sum_{k=0}^{\infty}(-1)^k\frac{(\frac{\pi}{4}l(z))^{2k}}{(2k)!}I_{n+1} + \sum_{k=0}^{\infty}(-1)^k\frac{i(\frac{\pi}{4}l(z))^{2k+1}}{(2k+1)!}X_{n+1}\\ &= \cos(\frac{\pi}{4}l(z))I_{n+1} + i\sin(\frac{\pi}{4}l(z))X_{n+1} \end{aligned} we can then rewrite the product in matrix form: \begin{aligned} U_l^{\dagger}Y_{n+1}U_l &= \begin{pmatrix} \cos(\frac{\pi}{4}l(z)) & -i\sin(\frac{\pi}{4}l(z))\\ -i\sin(\frac{\pi}{4}l(z)) & \cos(\frac{\pi}{4}l(z)) \end{pmatrix} \begin{pmatrix} 0 & -i\\ i & 0 \end{pmatrix} \begin{pmatrix} \cos(\frac{\pi}{4}l(z)) & i\sin(\frac{\pi}{4}l(z))\\ i\sin(\frac{\pi}{4}l(z)) & \cos(\frac{\pi}{4}l(z)) \end{pmatrix}\\ &= \begin{pmatrix} \sin(\frac{\pi}{2}l(z)) & -i\cos(\frac{\pi}{2}l(z))\\ i\cos(\frac{\pi}{2}l(z)) & -\sin(\frac{\pi}{2}l(z)) \end{pmatrix}\\ &= \cos(\frac{\pi}{2}l(z))Y_{n+1} + \cos(\frac{\pi}{2}l(z))Z_{n+1} \end{aligned} and we finally get the expected result.
• Is this the expected result though? The equation you quoted contained operator-valued terms $l(Z)$, and their notation suggests that $U_l^\dagger Y_{n+1} U_l$ is represented with a $2^{n+1}$-dimensional matrix, not a $2 \times 2$ matrix. Commented Oct 20, 2022 at 18:44
• You're right I should replace $l(z)$ by $l(Z)$ to be exact. Since $l(Z)$ is diagonal in the Z-basis you have an operator $\cos(\frac{\pi}{2}l(Z))$ (or $\sin(\frac{\pi}{2}l(Z))$) acting on the first $n$ qubits and the operator $Y_{n+1}$ or ($X_{n+1}$ ) acting on the last qubit that we want to measure Commented Oct 21, 2022 at 7:52