# How can you create S-GATE with U3?

Hello I am trying to create an Q0->HSSH Q1->HSH using U3 Gate only.

I am trying U3(pi/2, 0, pi) for H Gate and U3(4pi/2, 2pi,0) for S gate.

The output state vector using normal H and S gate don't seem to match the output from U3. Am I not understanding something correctly?

The U3-gate is quite versatile, as it can be used to construct many other standard gates. For example: \begin{align*} U_3 (\theta=\frac{\pi}{2}, \phi= 0, \lambda=\pi) &= \begin{bmatrix} \cos(\theta/2) & -e^{-i\lambda}\sin(\theta/2) \\ e^{i\phi}\sin(\theta/2) & e^{i(\lambda + \phi)}\cos(\theta/2) \end{bmatrix} \\ &= \begin{bmatrix} \cos(\pi/4) & -(-1)\sin(\pi/4) \\ 1 \sin(\pi/4) & -1 \cos(\pi/4) \end{bmatrix}. \end{align*} With: \begin{align*} \cos{\frac{\pi}{4}} = \sin{\frac{\pi}{4}} = \frac{1}{\sqrt{2}}, \end{align*} we are able to construct a Hadamard gate: \begin{align*} \Rightarrow U_3 (\frac{\pi}{2}, 0, \pi) &= \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} = H \end{align*}
Another example is how to construct the flexible phase gate $$U_1$$ (with which we can generate the P-gate, S-gate, and T-gate): \begin{align*} \Rightarrow U_3 (0, 0, \lambda) &= \begin{bmatrix} \cos(\theta/2) & -e^{-i\lambda}\sin(\theta/2) \\ e^{i\phi}\sin(\theta/2) & e^{i(\lambda + \phi)}\cos(\theta/2) \end{bmatrix} \\ &= \begin{bmatrix} 1 & 0 \\ 0 & e^{i\lambda} \end{bmatrix} \\ &= U_1. \end{align*} Specifically, to generate a Z-gate: $$U_3(0, 0, \pi) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\pi} \end{bmatrix} = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} = Z$$ And, similarly, the S-gate: $$U_3(0, 0, \pi/2) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\pi/2} \end{bmatrix} = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix} = S$$