# Preparing a linear combination of two $1$-occupied states

I apologize for a simple question, should be quite trivial. How do I construct a circuit for preparing such a state? $$|0\rangle^n \mapsto \cos(\theta)|0...0\underset{i}{1}0...0\rangle + \sin(\theta) |0...0\underset{j}{1}0...0\rangle \ ,$$ where the $$i$$th and $$j$$th qubits are in the $$|1\rangle$$ state.

Here is an example of such circuit for five qubits.

A gate $$Ry$$ acting on qubit $$q_1$$ prepares superposition

$$\cos(\theta/2)|0\rangle + \sin(\theta/2)|1\rangle.$$

When qubit $$q_1$$ is in state $$|0\rangle$$ (with probability $$\cos^2(\theta/2)$$), qubit $$q_3$$ is in state $$|1\rangle$$ thanks to gate $$X$$.

When qubit $$q_1$$ is in state $$|1\rangle$$ (with probability $$\sin^2(\theta/2)$$), qubit $$q_3$$ is in state $$|0\rangle$$ thanks to gate $$X$$ and CNOT gate (two negation is equal to no negation).

Other qubits are not changed and remain in state $$|0\rangle$$. As a result, the circuit produce state $$\cos(\theta/2)|00010\rangle + \sin(\theta/2)|01000\rangle.$$

You can construct similar circuit for any positions $$i$$ and $$j$$ simply by putting $$Ry$$ gate with proper parameter $$\theta$$ on one qubit, gate $$X$$ on second qubit and then "connect" them with CNOT gate.

• Thanks, exactly what I needed! – mavzolej Apr 15 at 15:01