enter image description here

 operation Algorithm() : Unit
    using (register = Qubit[4])

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.


1 Answer 1


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[3]);

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

To address the updated 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.
  • $\begingroup$ When i intialize this second register will it be a completely different variable? $\endgroup$
    – Mridul
    Jun 30, 2020 at 11:06
  • $\begingroup$ The second line is causing me a whole other layer of confusion. When researching other implementations it was left as an oracle to mark these states. I think a phase flip would be ideal, though this paper mentions this must be done in log(n) so iterating through the table and flipping each one wouldn't be ideal. $\endgroup$
    – Mridul
    Jun 30, 2020 at 11:09
  • $\begingroup$ Yes, second register should be a separate variable (so you'd say "using (r1, r2) = (Qubit[4], Qubit[4])" when allocating them) $\endgroup$ Jun 30, 2020 at 16:51
  • $\begingroup$ Thank you so much! this has cleared up a huge confusion ive had when implementing this alg. I was under the impression I needed to use tensor multiplication to achieve the initialized state. $\endgroup$
    – Mridul
    Jun 30, 2020 at 18:19
  • 1
    $\begingroup$ @Mridul: Tensor products are how we use math to represent the joint state of two unentangled registers, but aren't represented in quantum programs directly. Rather, you can just allocate both registers as Mariia describes. $\endgroup$ Jun 30, 2020 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.