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:

First attempt at fourth root

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:

Quirk Snapshot


2 Answers 2


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$.

enter image description here

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.

enter image description here

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

enter image description here

  • $\begingroup$ Thanks, that's even simpler. But what was wrong with my circuit that uses two ancillas? Did I phase it wrong? $\endgroup$ Commented Mar 4, 2022 at 17:35
  • $\begingroup$ @MarkS Ah you read it before I got the rest of the answer in. $\endgroup$ Commented Mar 4, 2022 at 17:44
  • $\begingroup$ 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! $\endgroup$ Commented Mar 4, 2022 at 18:31
  • $\begingroup$ 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. $\endgroup$ 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 enter image description here

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).

  • $\begingroup$ 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$? $\endgroup$ Commented Mar 4, 2022 at 14:59
  • $\begingroup$ 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)$. $\endgroup$
    – DaftWullie
    Commented Mar 4, 2022 at 15:05
  • $\begingroup$ 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 (?) $\endgroup$ Commented Mar 4, 2022 at 15:11

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.