# Entangling a register with another register using phase flips operation Algorithm() : Unit
{
using (register = Qubit)
{
within
{
PrepareUniformSuperposition(4,LittleEndian(register));
ApplyToEach(register,register);
}



I am having trouble with the ApplyToEach line. I am wondering if there is a way to entangle all the qubits in my register with another qubit, more broadly the 2(a) line 1. To my understanding I am satisfying the j term with uniform superposition. I am under the impression that when I apply the y-th qubit to my register I will entangle them. Maybe I am using the term entanglement wrong.

ApplyToEach operation applies an operation to each element of the array, you can't apply a qubit to each element of the array.

It sounds like you're trying to prepare a state in which all qubits will be entangled (the definition of entanglement is that you can't represent a state of the system as a tensor product of states of subsystems, so entangling each qubit with one of them will mean the whole system will be entangled). There are lots of ways to do this (since there are a lot of entangled states); if you don't care which state it is, the first thing that comes to mind is applying a Controlled Z gate to change the phase of the $$|1...1\rangle$$ state to $$-1$$:

Controlled Z(register[0..2], register);


If you're looking to prepare a specific state, you might want to clarify this in the question.

• You need to allocate two registers, one to hold the values $$|j\rangle$$ and another to hold the values $$|y\rangle$$.
• The first line of 2(a) is almost satisfied with PrepareUniformSuperposition: after this the first register will hold $$\sum_j\frac{1}{\sqrt{N}}|j\rangle$$ and the second one $$|0\rangle$$.
• To finish preparing the state described in the first line of 2(a) you need to prepare the state $$|y\rangle$$ on the second register. That can be done by converting $$y$$ to binary and applying X gate to each qubit that corresponds to 1 bit.
• To implement the second line of 2(a), you need to write some extra code that compares $$j$$ with $$y$$ and "marks" the state (I'm assuming flips the phase? It's not clear from the screenshot) - this step will indeed entangle the qubits of the two registers. You might want to read more about reversible computing and quantum oracles to do this.