# How does one derive quantum gates from a custom gate systematically?

I have been trying to solve a puzzle (not homework) in which I need to derive a quantum circuit from given a superposition, $$|\psi\rangle$$, where

$$|00\rangle: 20\%\\ |10\rangle: 40\%\\ |11\rangle: 40\%\\$$

and I must generate an output of

$$|00\rangle: 20\%\\ |11\rangle: 80\%\\$$

I started by writing $$|\psi\rangle$$ out as a ratios of the input probabilities wich somehow has to get to the output via a transformation C $${\Huge C}\begin{bmatrix}1 \\\ 0 \\\ 2\\\ 2 \end{bmatrix}=\begin{bmatrix}1 \\\ 0 \\\ 0\\\ 4 \end{bmatrix}$$

It was then simple enough to determine that what was actually happening was $${\Huge C}=\begin{bmatrix}1 & 0 & 0 & 0\\\ 0 & 0 & 0 & 0\\\ 0 & 0 & 0 & 0\\\ 0 & 0 & 1 & 1\end{bmatrix}$$

My question is then, how can I derive which primitive quantum logic gates should be used to compose this operation, C? Even if it is intuitive to some people, I cannot recognise it and would appreciate a step-by-step way to break it down into regular gates. Ideally the solution would be able to generalise for other situations where I need to derive what logic gates are used to produce certain results.

If there is a problem with the formulation of the question or terminology used, feel free to suggest an edit. I am quite new to this.

## Edit 1

Thanks for the comments. I have been working through the terminology in what you all have said and I can provide some amended information (though I can't personally see how it has a bearing on the solution).

The puzzle actually has a way of getting the amplitudes, yet none of them have a complex component. So if I got his right, the input state vector looks like this:

$$\begin{bmatrix}\sqrt{0.2} + 0i \\\ 0 \\\ \sqrt{0.4} + 0i\\\ \sqrt{0.4} + 0i \end{bmatrix}$$

I also have no idea how to represent the "desired" vector. I do now understand why whatever C is needs to be unitary, but I don't know how to get a C at all now.

• C isn't unitary so it's not a quantum operation. Mar 9, 2022 at 17:09
• State vector should be amplitudes, not probabilities, no? And these may be complex-valued. Mar 9, 2022 at 17:50
• Your general approach of inverting $C$ is not bad but your matrix $C$ is not reversible/unitary. See here. Also your wavefunction $|\psi\rangle$ is composed of probabilities, but it needs to be amplitudes/roots of probabilities. Mar 9, 2022 at 18:11
• controlled-Hadamard controlled off the first qubit targeting the second qubit. $$\left(\begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1/\sqrt{2} & 1/\sqrt{2} \\ 0 & 0 & 1/\sqrt{2} & -1/\sqrt{2} \end{array}\right)$$. Mar 10, 2022 at 15:24

A quantum system is not specified by probabilities, but probability amplitudes. I'm going to assume that what you want to do is the conversion $$\frac{1}{\sqrt{5}}\left(\begin{array}{c} 1 \\ 0 \\ \sqrt{2} \\ \sqrt{2} \end{array}\right)\rightarrow\frac{1}{\sqrt{5}}\left(\begin{array}{c} 1 \\ 0 \\ 0 \\2 \end{array}\right)$$ The way that I look at this, it says that the amplitudes on the states where the first qubit is in $$|0\rangle$$ just stay the same. I only have to change things if the first qubit is in the $$|1\rangle$$ state. Hence, we're looking for a unitary controlled-$$U$$ where $$U\frac{1}{\sqrt{5}}\left(\begin{array}{c} \sqrt{2} \\ \sqrt{2} \end{array}\right)=\frac{1}{\sqrt{5}}\left(\begin{array}{c} 0 \\ 2 \end{array}\right),$$ subject to the constraint that $$U$$ is unitary, meaning $$UU^\dagger=I$$ and $$U^\dagger U=I$$. You can construct such a matrix very easily. In particular, multiply both sides of the previous equation by $$U^\dagger$$. We have $$U^\dagger\left(\begin{array}{c} 0 \\ 1 \end{array}\right)=U^\dagger U\frac{1}{\sqrt{2}}\left(\begin{array}{c} 1 \\ 1 \end{array}\right)=\frac{1}{\sqrt{2}}\left(\begin{array}{c} 1 \\ 1 \end{array}\right).$$ Now, let's temporarily write out $$U^\dagger=\left(\begin{array}{cc} a & b \\ c & d \end{array}\right).$$ Hence, $$U^\dagger\left(\begin{array}{c} 0 \\ 1 \end{array}\right)=\left(\begin{array}{c} c \\ d \end{array}\right).$$ Thus, we can easily identify the elements $$c$$ and $$d$$ as both being $$\frac{1}{\sqrt{2}}$$. We have identified the second column of $$U^\dagger$$.
So, if we can identify the first column, i.e. the values $$U^\dagger\left(\begin{array}{c} 1 \\ 0 \end{array}\right),$$ we're done. Note, however, that $$\left(U^\dagger\left(\begin{array}{c} 0 \\ 1 \end{array}\right)\right)^\dagger U^\dagger\left(\begin{array}{c} 1 \\ 0 \end{array}\right)=\left(\begin{array}{cc} 1 & 0 \end{array}\right)UU^\dagger\left(\begin{array}{c} 1 \\ 0 \end{array}\right)=\left(\begin{array}{cc} 1 & 0 \end{array}\right)\left(\begin{array}{c} 1 \\ 0 \end{array}\right)=0$$ but it is also $$=\left(\begin{array}{cc} a^\star & b^\star \end{array}\right)\left(\begin{array}{c} c \\ d \end{array}\right)=a^\star c+b^\star d.$$ Said another way, the first column must be orthogonal in order to give unitarity. Also, each column must have length 1. There's some freedom in the choice - we can have any $$a=e^{i\phi}$$ with $$b=-e^{i\phi}$$, but a natural one would be $$\phi=0$$, thus giving $$U^\dagger=\frac{1}{\sqrt{2}}\left(\begin{array}{cc} 1 & 1 \\ -1 & 1 \end{array}\right)=\sqrt{Y}$$ and hence $$U=\sqrt{Y}^\dagger.$$ Thus, the overall operation you're looking for is controlled-$$\sqrt{Y}^\dagger$$, which is written as $$\left(\begin{array}{cccc} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 \\ 0 & 0 & \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \\ 0 & 0 & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \end{array}\right)$$
• You mean the bit that goes from the action of $U$ on one particular vector to producing the matrix form of $U$? Mar 15, 2022 at 11:01