# How to visualize Hadamard gate as $X$-$Z$-$X$ decomposition?

In the book Quantum Computation and Quantum Information by Nielsen and Chuang, chapter 4, exercise 4.4 (pg. 175), the author has asked to express Hadamard gate as product of $$R_x$$, $$R_z$$ rotations and $$e^{i\phi}$$ for some angle $$\phi$$. I have found two answers for the same.

1. Rotating the Hadamard gate parallel to $$|0\rangle$$ performing the rotation about $$Z$$ axis and reverting back to original position. Elaborate mathematical visualisation can be found in the question asked here. Rewriting rotations as: $$\begin{array} \ &= e^{i\pi/2}R_z(-\pi/2)R_x(-\pi/4)R_z(\pi)R_x(\pi/4)R_z(\pi/2) \\ &= \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1\\ 1 & -1 \end{bmatrix}\\ &=H \end{array}$$ I have understood this decomposition very well. Though, its cumbersome to arrive write this decomposition. This led me to the second option.
2. The other way is analytically explained in this pdf. This yields $$X$$-$$Z$$-$$X$$ decomposition as: $$\begin{array} \ &= e^{i\pi/2}R_x(\pi/2)R_z(\pi/2)R_x(\pi/2) \\ &= \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1\\ 1 & -1 \end{bmatrix}\\ &=H \end{array}$$

Now, how should I visualize, or intuitively arrive at this second decomposition?

The only way that comes to my mind is to transform $$|0\rangle$$ and $$\frac{|0\rangle + i|1\rangle}{\sqrt{2}}$$ around rotation vector of Hadamard gate under $$X$$-$$Z$$-$$X$$ transformation as discussed in point 1 (here). Are there better visualizations possible?

[First edit]

By visualization, I mean, the mental shortcut to decompose Hadamard gate into $$R_x(\beta)R_z(\gamma)R_x(\rho)$$, without doing the complete matrix multiplication, like,just knowing the Bloch angles made by the axis of rotation of Hadamard gate I can decompose it as $$R_z(-\pi/2)R_x(-\pi/4)R_z(\pi)R_x(\pi/4)R_z(\pi/2)$$ without bothering to multiply five $$2X2$$ matrices.

As mentioned in the other answer, the Hadamard gate is a pi rotation (180 degree) around the $$X + Z$$ axis. That is, it is a 180 degree rotation around the purple axis indicated in the below figure:

And the $$Rx(\pi/2)$$ follows by a $$Rz(\pi/2)$$ then follow by $$Rx(\pi/2)$$ does exactly this rotation as well.

To have better visualization of this, suppose I start my qubit in the state $$|0\rangle$$ and I apply some rotation $$U$$ to it. Here, let's take $$U$$ to be: $$U = \begin{pmatrix} 0.11833 - 0.52719i & 0.18429 - 0.82104i \\ -0.18429 - 0.82104i & 0.11833 + 0.52719i \\ \end{pmatrix}$$

Which can be written as $$U = R_Y(-2)R_Z(2.7)$$. So we first apply $$R_Y(-2)$$ follow by $$R_Z(2.7)$$ then finally apply the Hadamard gate.

The reason to apply this $$U$$ is so that we get to a state that is non-trivial so we have better visualization of the rotation. In the animate below, the first two rotations correspond to the $$R_Y(-2)$$ then $$R_Z(2.7)$$. The last rotation correspond to the Hadamard rotation.

Keep an eye on the last rotation (Hadamard) as we will compare this to the rotation $$Rx(\pi/2)$$ follows by a $$Rz(\pi/2)$$ then follow by $$Rx(\pi/2)$$ next.

Here, we will consider the same starting point. That is, we again map start at the state $$|0\rangle$$ then apply $$U = R_Y(-2)R_Z(2.7)$$. But instead of applying the Hadamard gate, we will apply the rotations $$Rx(\pi/2)Rz(\pi/2)Rx(\pi/2)$$. That is,

So watch the last three rotations carefully. You can see that it reaches to the same final point as previously.

Side to side comparison:

• I guess the question is misunderstood. Let me reiterate my point using your example. Consider the arbitrary unitary vector $U$ chosen by you. If one knows the axis about which it is causing the rotation, then, I can easily decompose $U$ as $R_z(-\lambda)R_x(-\phi)R_z(\theta)R_z(\lambda)R_x(\phi)$ without doing the matrix multiplication. But, If I have to find $(\beta,\gamma,\rho)$ such that $R_x(\beta)R_z(\gamma)R_z(\rho)=U$, then, I don't have any clue. Basically, how to solve $U=R_x(\beta)R_z(\gamma)R_z(\rho)$, without the heavy matrix multiplication (it a complex matrix)? Jun 22, 2021 at 2:56
• What function should I use to do the same animation? Aug 14, 2021 at 9:37
• HI @narip, I think I used qiskit visualization for this one. Aug 14, 2021 at 21:16

Any gate in the circuit can be seen as an element of SU(2), ignoring the global phase. Hence Hadamard gate can be changed into $$\sqrt{1/2}\begin{pmatrix} i & i\\ i & -i \end{pmatrix}.$$ And any element of SU(2) $$\begin{pmatrix} a & b\\ -b^* & a^* \end{pmatrix}$$can be changed into SO(3) with the formula below, which you can find it in some books about group theory: $$\left(\begin{array}{ccc} \frac{1}{2}\left(a^{2}+a^{* 2}-b^{2}-b^{* 2}\right) & -\frac{i}{2}\left(a^{2}-a^{* 2}+b^{2}-b^{* 2}\right) & -\left(a b+a^{*} b^{*}\right) \\ \frac{i}{2}\left(a^{2}-a^{* 2}-b^{2}+b^{* 2}\right) & \frac{1}{2}\left(a^{2}+a^{* 2}+b^{2}+b^{* 2}\right) & i\left(a^{*} b^{*}-b a\right) \\ a^{*} b+b^{*} a & i\left(a^{*} b-b^{*} a\right) & a a^{*}-b b^{*} \end{array}\right) .$$ Therefore, the corresponding SO(3) element of Hadamard gate can be calculated to be $$\begin{pmatrix} 0 & 0 & 1\\ 0 & -1 & 0\\ 1 & 0 & 0 \end{pmatrix}$$. And the rotation axis can be calculated by solving the eigenvector problem, and the proper rotation axis should have the eigenvalue 1 instead of -1. So the final rotation axis is: $$\begin{pmatrix} 1/\sqrt2\\ 0\\ 1/\sqrt2 \end{pmatrix}.$$ Conclusion: it's a $$\pi$$ rotation around $$\begin{pmatrix} 1/\sqrt2\\ 0\\ 1/\sqrt2 \end{pmatrix}$$ axis. To check the correctness of it, $$| 0\rangle$$ corresponds to $$(0,0,1)^T$$ and after the rotation it becomes $$(1,0,0)^T$$, which is $$| 1\rangle$$, and the same can be done with $$1/\sqrt2(| 0\rangle+i| 1\rangle)$$, ignoring the global phase.