# Error estimate for finite approximation of Hadamard gate from two rotations

I was teaching myself some fundamentals about quantum computing with qiskit while I stumbled upon a challenge I am not able to solve. One problem discusses how one can implement the Hadamard gate (in the $$\sigma_z$$ eigenbasis),

$$H=\frac{\sigma_x+\sigma_z}{\sqrt{2}}=\frac{1}{\sqrt{2}}\begin{pmatrix}1 & 1 \\ 1 & -1\end{pmatrix},\tag{1}$$

by using the state rotations,

\begin{align} R_x(\theta)=\exp\{i\theta\sigma_x/2\}, && R_z(\theta)=\exp\{i\theta\sigma_z/2\},\tag{2} \end{align}

wherein $$\sigma_x,\sigma_y,\sigma_z$$ are the Pauli matrices. More precisely, we are given,

$$H=\exp\left\{i\frac{\pi}{2}H+i\varphi\right\}\tag{3},$$

which can be proven by using noting that the Hadamard operator $$H$$ is unitary and hermitian, therefore, $$H^2=1$$ which combined with the series representation of the exponential again gives us the Hadamard operator $$H$$ up to a global phase.

Furthermore, we are said that for,

$$H_n=\left(R_x(\theta/n)R_z(\theta/n)\right)^n,\tag{4}$$

we have $$H_n\xrightarrow{n\to\infty}H$$ for the right choice of $$\theta$$.

When we visualize the Hadamard operator as rotation on the Bloch sphere, see Visual interpretation, on the Bloch sphere, when Hadamard gate is applied twice, Eq. (4) makes sense in that we do a small rotation around the $$x$$ axis, followed by a small rotation around the $$z$$ axis, and this repeated over and over.

Finally, there is the claim that the error reduces quadratic with $$n$$. I would now like to give an explicit expression for the error in terms of $$n$$.

### Attempt 1: Rotation matrices

We can use the identity,

$$\exp\left\{i\theta\sigma_i/2\right\} =1\cos\frac{\theta}{2}+i\sigma_i\sin\frac{\theta}{2},\tag{5}$$

to calculate,

\begin{align} R_x(\theta/n)R_z(\theta/n) &=\left(1\cos\frac{\theta}{2n}+i\sigma_x\sin\frac{\theta}{2n}\right)\left(1\cos\frac{\theta}{2n}+i\sigma_z\sin\frac{\theta}{2n}\right)\\ &= \begin{pmatrix} \cos\frac{\theta}{2n} && i\sin\frac{\theta}{2n}\\ i\sin\frac{\theta}{2n} && \cos\frac{\theta}{2n} \end{pmatrix} \begin{pmatrix} \cos\frac{\theta}{2n}+i\sin\frac{\theta}{2n} && 0\\ 0 && \cos\frac{\theta}{2n}-i\sin\frac{\theta}{2n} \end{pmatrix}\\ &= \frac{1}{2} \begin{pmatrix} 1+\exp\{+\frac{i\theta}{n}\} && 1-\exp\{-\frac{i\theta}{n}\}\\ -1+\exp\{+\frac{i\theta}{n}\} && 1+\exp\{-\frac{i\theta}{n}\} \end{pmatrix},\tag{6} \end{align}

however, I don't see how this can lead to the Hadamard gate.

### Attempt 2: Baker-Campbell-Hausdorff formula

The Baker-Campbell-Hausdorff (BCH) formula states,

$$e^Xe^Y=e^{X+Y+\frac{1}{2}[X,Y]+\dots},\tag{7}$$

for non-commutative $$X,Y$$ in a Lie algebra. The Pauli matrices form a Lie algebra, henceforth,

$$R_x(\theta/n)R_z(\theta/n) =\exp\left\{\frac{i\theta}{2n}\sigma_x\right\}\exp\left\{\frac{i\theta}{2n}\sigma_z\right\} =\exp\left\{\frac{i\theta}{2n}(\sigma_x+\sigma_z)+i\frac{\theta^2}{4n^2}\sigma_y+\mathcal{O}\left(\frac{1}{n^3}\right)\right\},\tag{8}$$

where we have used $$[\sigma_x,\sigma_z]=-2i\sigma_y$$. Using the exponential series representation and neglecting higher orders of $$1/n$$, we find,

$$R_x(\theta/n)R_z(\theta/n)=1+\frac{i\theta}{2n}(\sigma_x+\sigma_z)+\frac{i\theta^2}{4n^2}\sigma_y-\frac{\theta^2}{4n^2}(\sigma_x+\sigma_z)^2+\mathcal{O}\left(\frac{1}{n^3}\right). \tag{9}$$

By noting $$(\sigma_x+\sigma_z)^2=1+\{\sigma_x,\sigma_z\}+1=2$$, we can simplify Eq. (5) to,

$$R_x(\theta/n)R_z(\theta/n) =1+\frac{i\theta}{2n}(\sigma_x+\sigma_z)+\frac{i\theta^2}{4n^2}\sigma_y-\frac{\theta^2}{2n^2}+\mathcal{O}\left(\frac{1}{n^3}\right).\tag{10}$$

From my dark analysis days, I remember that,

$$\lim_{n\to\infty}\left(1+\frac{x}{n}\right)^n=e^x.\tag{11}$$

If I assume $$n\gg1$$ and multiply out the powers while neglecting higher orders of $$1/n$$ I find,

\begin{align} H_n &=(R_x(\theta/n)R_z(\theta/n))^n\\ &=\left(1+\frac{i\theta}{2n}(\sigma_x+\sigma_z)\right)^n+\frac{\theta^2}{4n^2}(i\sigma_y-2)+\mathcal{O}\left(\frac{1}{n^3}\right)\tag{12}\\ &=H+\frac{\theta^2}{4n^2}(i\sigma_y-2)+\mathcal{O}\left(\frac{1}{n^3}\right),\tag{13} \end{align}

however, I don't feel very comfortable with the last step as we keep higher-order $$1/n$$ terms for the first term in Eq. (12) but we drop them for the second (and higher) terms in Eq. (12). In addition, we take the limit $$n\to\infty$$ on the first term of Eq. (12) to recover the Hadamard operator $$H$$ but we don't do the same for the second term of Eq. (12) to arrive at Eq. (13).

If Eq. (13) is correct, we can check Eq. (3) to find that $$\theta=\pi/\sqrt{2}$$.

### Error of the measurement

Given an initial (qubit) state,

$$\vert 0\rangle=\begin{pmatrix}1\\0\end{pmatrix},$$

the qiskit article proposes to use,

$$E=\vert\langle0\vert H_nH\vert0\rangle\vert^2-1,\tag{14}$$

as an error estimate. For $$E\xrightarrow{n\to\infty}0$$, i.e. there would be no error because of $$H^2=1$$. For finite $$n$$ Eq. (13) would give us,

\begin{align} E &=\left\vert\langle0\vert\frac{\pi^2}{8n^2}(i\sigma_y-2)\frac{1}{\sqrt{2}}H\vert0\rangle\right\vert^2\\ &=\left\vert \begin{pmatrix}1 && 0\end{pmatrix}\frac{\pi^2}{16n^2}\begin{pmatrix}-2 && 1\\-1 && -2\end{pmatrix}\begin{pmatrix}1 && 1\\1 && -1\end{pmatrix}\begin{pmatrix}1 \\ 0\end{pmatrix} \right\vert^2\\ &=\left(\frac{\pi}{4n}\right)^4.\tag{15} \end{align}

Comparing the expression for the error in Eq. (15) with a simulation: We find that $$(\pi/4)^4\approx0.38$$, $$(\pi/8)^4\approx0.024$$. Thus, something is wrong.