# Approximating unitary matrices -- restricted gateset

Note: This question is a follow up of Approximating unitary matrices.

The decompositions provided in Approximating unitary matrices are correct and worked for me without problem.

But I am now facing an issue: I want to try to optimise my circuit, and the method I want to use restricts the gate-set I can afford to use. The solution given in the previous post is no longer usable for me, because the gate-set I can use does not contain all the gates used in the solution.

My problem is the following: I need to approximate the following quantum gate $$W = \begin{pmatrix} 1&0&0&0\\ 0&\frac{1}{\sqrt{2}}&\frac{1}{\sqrt{2}}&0\\ 0&\frac{1}{\sqrt{2}}&\frac{-1}{\sqrt{2}}&0\\ 0&0&0&1 \\ \end{pmatrix}$$ with the gate-set $$\left\{ H, X, R_\phi, \text{C}R_\phi, R_z, \text{C}R_z, \text{C}X, \text{CC}X \right\}$$ with $$R_\phi$$ defined as in Wikipedia, $$R_z$$ the rotation around the $$Z$$-axis and $$\text{C}$$ being a control (i.e. $$\text{CC}X$$ is the Toffoli gate, or double-controlled $$X$$ gate).

As shown by @Craig Gidney in his answer, this boils down to implement a controlled-$$H$$ gate with my gate-set, or equivalently a $$R_y\left( \frac{\pi}{4} \right)$$ gate.

I would love to have an exact decomposition, that is why I already tested:

• Using the following formula $$U = e^{i\alpha} R_z(\beta) R_y(\gamma) R_z(\lambda).$$ As I only need to implement $$R_y\left( \frac{\pi}{4}\right)$$ I replaced $$\gamma$$ by $$\frac{\pi}{4}$$ and searched for values of $$\beta$$ and $$\lambda$$ that would result in a gate $$U$$ that I can implement easily with my gate-set. I did not succeed, but finding a solution to this alternative problem would solve my original problem as the equation above is equivalent to: $$R_y(\gamma) = e^{-i\alpha} R_z(-\beta) U R_z(-\lambda)$$ and $$R_z$$ is in my gate-set.

• Trying to find a decomposition by playing with matrices, this approach did not work either, mostly because it was more random tries.

I no exact decomposition exist, I will end up using an algorithm like Solovay-Kitaev or Group Leader Optimisation, but introducing errors in this gate is a real issue as it is used extensively in all the quantum circuit.

You would be better off trying to write $$R_y(\pi/4)=e^{i\alpha}R_z(\beta)R_x(\gamma)R_z(\delta)=e^{i\alpha}R_z(\beta)HR_z(\gamma)HR_z(\delta)$$ and solving for the parameters in there.

By the way, what you're essentially interested in is $$\sqrt{Z}R_x(\pi/4)\sqrt{Z}^\dagger$$, up to some possible phases. Hopefully that indicates what angles of rotation you're going to be wanting.