# Shor's implementation problem on qiskit

1. If q4-7 are all supposed to be eigenstates of the operation, why is it just that q7 is in $$|1\rangle$$? Shouldn't all qubits 4 to 7 be in the $$|1\rangle$$ state to kick back phases from the $$Rz$$ gates applied?

2. I'm trying to see what's inside each of those controlled operations, and as observed below it's a bunch of swap gates. How do swap gates do any meaningful computation? How do they kickback an important phase? I was expecting same quantum gates applied on the eigenstate such that an important phase gets kicked up, so I don't see the point in swap gates.

First question

There are two implementation of Shor algorithm. The first one is depicted in this picture:

In this case, a function $$a^x \mod N$$ is implemented in $$U_f$$ gate and you are trying to find period in such function.

Another implementation (yours one) uses phase estimation for finding the period. See thsis implementation on Wiki for example.

In the first case, all qubits are initialized to $$|0\rangle$$. In second case as you can see in Wiki link, qubits used as input to an "operator which phase is estimated" are initialized at $$|1\rangle$$. It seems that part of $$X$$ gates are included into controlled operators (sorry I have not enought time to reconstruct the opeators).

Second question

As the operators are controlled ones, bottom qubits are entangled with top qubits which allow phase kick-back. As a result, you are able to measure the phase on top qubits.

Concerning swap gate, even such gates are able to perform calculation. You can see here how swap gates implement modular multiplication used in the Shor algorithm.

How do swap gates do any meaningful computation? How do they kickback an important phase? I was expecting same quantum gates applied on the eigenstate such that an important phase gets kicked up

What makes you think swap gates can't have phase kickback? The swap operation has both +1 and -1 eigenspaces. For example:

I’m going to add a clarification as to why the $$X$$ gate is applied to only one qubit on the second register as the other answers don’t seem to address this in detail.

In the Shor’s Algorithm chapter of the Qiskit Textbook, it is shown that $$|1\rangle$$ is the superposition of all eigenstates of $$U$$. However, you need to be careful with notation here. Notice that in all the expandable blocks where they explain the derivations in detail, they are using decimal rather than binary numbers. For example:

$$|u_0\rangle = \frac{1}{12} ( | 1\rangle + |3\rangle + |9\rangle + \cdots + |4\rangle + |12\rangle)$$

Therefore you need to treat all these numbers on these expressions as decimals. The confusion comes when we are left only with $$|1\rangle$$, as we may think it refers to $$|1\rangle^{\otimes n}$$ where $$n$$ is the number of qubits. But since it is a decimal, it translates to binary as $$|00\cdots1\rangle$$, i.e. 0’s everywhere except for the bit corresponding to $$2^0$$.