# Unexpected Relative Phase while making the Toffoli Gate

I was trying to build the Toffoli gate using the following diagram (found in the qiskit textbook):

So, I set V := Rx(pi/2) (as shown in the following diagram) (Note: that I am switching now to the little-endian format)

However, the unitary matrix equivalent to the previous was

$$\begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & -i\\ 0 & 0 & 0 & 0 & 0 & 0 & -i & 0\\ \end{pmatrix}$$

That will lead to a relative phase of $$(-i)$$ in the states $$\lvert 110 \rangle$$ and $$\lvert 111 \rangle$$

What is the reason for that?

$$R_x(\pi/2)$$ isn't a square root of the X gate. If you square it, you get $$-iX$$ instead of $$X$$. That's where the phase is coming from.