# What is wrong with my circuit for the fourth-root of $X$?

For learning purposes I would like to hand-craft my own circuit for the fourth-root of $$X$$, using $$S$$, $$T$$, and $$\sqrt X$$ gates.

Note that $$\sqrt[4]X$$ is of order eight while $$\sqrt X$$ is of order four, and we can use two ancillas to temporarily store the respective eigenspace. The recipe that I have been following is to:

1. Hit both ancilla with a Hadamard $$H$$,
2. Have the lower-order ancilla perform a controlled $$\sqrt X$$ on the target with the higher-order ancilla perform a controlled $$X$$ on the target,
3. Perform a QFT on the ancillas,
4. Phase the ancillas,
5. Perform an IQFT on the ancillas,
6. Have the higher-order ancilla perform another controlled $$X$$ while the lower-order ancilla performs a controlled $$X^{-1/2}$$, and
7. Hit both ancillas with an $$H$$ to revert:

I try the above circuit in Quirk; although the ancillas properly revert $$|0\rangle$$, it gives me a different answer on the target than Quirk's native $$\sqrt[4] X$$. On the Bloch sphere my recipe says the target's $$\theta$$ is $$135^\circ$$ while the native $$\sqrt[4] X$$ should be at $$45^\circ$$.

Did I get my endian-convention wrong on the QFT (red)? Or did I do the uncomputing wrong? Did I not phase properly (purple)?

Here's a Quirk snapshot to compare. The hand-crafted circuit is on the first three qubits with the ancilla the first two qubits and the target the third qubit, while the native $$\sqrt[4] X$$ for comparison is the fourth qubit. The Bloch spheres/amplitudes are different between the third qubit (my circuit) and Quirk's native circuit:

With the gates you allowed, you can conjugate the $$T$$ so that it rotates around $$X$$ instead of $$Z$$. That gives you $$\sqrt[4]X$$.

In your circuit I think you got your QFTs backwards, so the phase estimation is estimating the negation of the phase. This is negating the rotation you apply, and making both bits of the phase estimation register relevant instead of just one as should be the case for this case.

Also I think you got your endianness backwards. The S and the T in the center might be in the wrong order. This might be because you didn't include swaps as part of your decomposed QFTs.

An endian error and a sign error. The eternal struggle against mundane mistakes continues. Fixing them both makes it work.

or, using the built-in QFT (and switching some other endian stuff):

• Thanks, that's even simpler. But what was wrong with my circuit that uses two ancillas? Did I phase it wrong? Commented Mar 4, 2022 at 17:35
• @MarkS Ah you read it before I got the rest of the answer in. Commented Mar 4, 2022 at 17:44
• Yay! Hurray! This works. Thanks! The ancilla serving as the MSB (the one that controls the $X$ and not the $X^{1/2}$) goes from seeing a $T$ gate with the hand-crafted QFT to seeing an $S$ gate with the built-in QFT because I didn't SWAP them. Getting clear now. Thanks! Commented Mar 4, 2022 at 18:31
• BTW thanks a bunch for Quirk. It's really fun and intuitive to use. I've spent half of today building circuits to take the roots of rotations of vertices of a square. Commented Mar 5, 2022 at 0:02

I think it's actually far easier than this. You only need one ancilla. The trick is that $$X$$ has the same eigenvectors as $$\sqrt[4]X$$. So, you can just do the following

The circuit that you've attempted is for when you've already got a controlled-$$U$$ for which the eigenvalues of $$U$$ $$\omega$$ with $$\omega^4=1$$. What you're trying to do is construct the effect of such a $$U$$ starting from a controlled-$$V$$ where $$V^2=I$$ so you only need one ancilla (basically, to detect if the bottom qubit is in the $$|+\rangle$$ state (don't add a phase) or the $$|-\rangle$$ state (add a phase).

• I understand your circuit, but I don't understand the comment or the relevance that $X$ has the same e'vectors as $\sqrt[4] X$? I thought $X$'s e'vals are $\pm 1$, while $\sqrt[4] X$'s e'vals are $\pm 1, \pm i$? Commented Mar 4, 2022 at 14:59
• Yes, but what you're trying to do is create a separation based on the eigenvectors, so $|0\rangle(\alpha|+\rangle+|\beta|-\rangle)\rightarrow \alpha|0+\rangle+\beta|1-\rangle$ so that you can crate the eigenvalues by applying phases on the ancilla, $\rightarrow \alpha|0+\rangle+e^{i\pi/4}\beta|1-\rangle$, before uncomputing the entanglement $\rightarrow |0\rangle(\alpha|+\rangle+e^{i\pi/4}\beta|-\rangle)$. Commented Mar 4, 2022 at 15:05
• Hmm... Let me think. If $U$ is some SWAP circuit that rotates the vertices of a square (so $U^4=\mathbb I$), that's different from trying to take the fourth root of a SWAP circuit that flips the square around a line through the middle (?) Commented Mar 4, 2022 at 15:11