# Getting intuition on the state-injection relations for the generalized $\exp(-iP \pi/8)$ $T$-gates (ideally using ZX calculus)

In Litinsky's paper, there are many circuits relations, like the one below.

The left handside represents the "rotation" $$\exp(-i P \phi)$$ with $$\phi=\pi/8$$ with similar definitions for the orange ($$\phi=\pi/4$$) and gray box ($$\phi=\pi/2$$) on the right hand side. The blue boxes represent multi-qubit Pauli measurements.

I managed to check all the relations he wrote through "brute force" algebra, but it doesn't give any intuition of "why" the circuit works (for instance how did he came with the idea that this equality would be true?). The circuit I have drawn is also only one of the many similar ones he uses.

I just learned the basics of ZX-calculus as it can help to understand circuit simplifications, and I would like to know if there is a simple way to show these equalities using ZX? This is my main question.

One of the issues I face is that I don't see a simple way to represent $$\exp(-i P \phi)$$ nor the multi-Pauli measurement in ZX (but I am also a beginner in ZX so perhaps there is a simple way I don't see).

If it appears ZX cannot help, but there is another way to show that these equalities are true, while giving some kind of intuition (i.e. not a "brute-force" matrix equality), I can be interested. There is such an answer there but it only shows the equality for a one qubit $$T$$-gate. I am not sure to see how the reasonning generalizes to a "multi-qubit $$T$$-gate"

TL;DR: The key idea that helps to translate these circuits into ZX diagrams is the interpretation of two strongly complementary spiders as the copy and parity operations$$^1$$. As expected, the ZX diagram for the circuit sheds some light on why it works. Namely, it shows that each of the three stages that depend on $$P$$ is actually a phasing operation and the relevant phase angles always add up to $$\frac{\pi}{4}$$.

## Diagonal operators from copy operation

Without loss of generality$$^2$$ assume that $$P=Z^{\otimes n}$$ and note that the matrix of $$P_\phi=\exp(-iZ^{\otimes n}\phi)$$ is diagonal in the computational basis. In other words, it takes the form $$P_\phi=\sum_i f(i)|i\rangle\langle i|\tag1$$ for some function $$f:\mathbb{Z}_2^n\to\mathbb{C}$$. Recall that the general zero-phase spider derived from the computational basis takes the form $$\sum_i|i\rangle^{\otimes k_1}\langle i|^{\otimes k_2}$$. Therefore, $$P_\phi$$ can be expressed as

where the question mark hides a subdiagram responsible for computing diagonal elements.

## Pauli exponentials from copy and parity operations

Moreover, $$P_\phi$$ applies the phase factor $$e^{i\phi}$$ to the basis states with odd Hamming weight and $$e^{-i\phi}$$ to the those with even Hamming weight. However, global phase is irrelevant, so we may equivalently say that $$P_\phi$$ applies the phase factor $$e^{2i\phi}$$ to the basis states with odd Hamming weight and does nothing to those with even Hamming weight. But parity is exactly what the strongly complementary spider computes, so we fill the rest of the diagram as

where we added an extra leg with a single-legged unfilled spider to introduce the actual phase factor $$e^{2i\phi}$$. This makes the operation unitary$$^3$$.

## Pauli projectors from copy and parity operations

Next, we note that if we had not added the extra leg in the last diagram, then it would instead represent a projection onto the subspace spanned by the computational basis vectors of even Hamming weight. Finally, it is not hard to check$$^4$$ that if the filled spider carries the phase angle $$\pi$$, then the parity is reversed and the operation is a projection onto the subspace spanned by the computational basis vectors of odd Hamming weight.

## Putting it all together

We now know how to represent each of the three stages of the circuit into ZX diagrams. Combining the results, we have

where $$x,z\in\{0,1\}$$ represent the two measurement outcomes$$^5$$. By applying the fusion rule and letting the filled $$\pi$$ spider act as a bit flip, we transform the last diagram into

At this stage, we could continue to use ZX calculus rewrite rules, but it is easier to note that each of the three stages is a phase gate $$\exp(-iZ^{\otimes n}\alpha)$$ for some $$\alpha$$. Moreover, we know$$^6$$ that $$\exp(-iZ^{\otimes n}\alpha)\exp(-iZ^{\otimes n}\beta)=\exp(-iZ^{\otimes n}(\alpha+\beta))\tag2$$ so it is easier to complete the proof using $$(2)$$. Indeed, all we need to do is check that $$(-1)^z\left[\frac{\pi}{4}+\pi x\right]+\frac{\pi z}{2}+\pi x\tag3$$ equals $$\frac{\pi}{4}$$ modulo $$2\pi$$ for all possible values of $$x,z\in\{0,1\}$$.

## Intuition behind the circuit

Intuitively, we can think of the circuit as consisting of two non-deterministic operations and their associated corrections. The first one is a joint entangling measurement of the input and an auxiliary qubit in the magic state. The second one is a disentangling measurement on the auxiliary qubit only. Since each of the two operations is non-deterministic, each may fail to perform the intended transformation. Therefore, each requires an optional correction in form of a classically controlled quantum gate.

In more detail, the first operation entangles the input with the magic state $$|m\rangle=|0\rangle+e^{i\pi/4}|1\rangle$$ in order to kick the phase factor $$e^{i\pi/4}$$ from the magic state to the $$-1$$ eigenspace of $$P$$. This succeeds if $$z=0$$. However, if $$z=1$$ then it ends up applying the $$e^{-i\pi/4}$$ phase factor instead. Should this happen, we apply the phase gate with $$e^{i\pi/2}$$ to get our desired $$e^{i\pi/4}$$ phase factor.

Second, we now have a state in which the input register is entangled with the auxiliary qubit. To break the entanglement we measure the latter. The ZX diagram above explains why we need a measurement in the $$X$$ basis. Namely, we need the overall diagram to represent a $$\exp(-iZ^{\otimes n}\phi)$$ for some $$\phi$$. The second operation is also non-deterministic and may sneak in an extra phase flip into the first rotation. If this happens, we compensate with another controlled rotation.

$$^1$$ This can also be expressed in the language of tensor networks, see example 4 on page 7 in this paper.
$$^2$$ The case of general $$P$$ follows from $$P=Z^{\otimes n}$$ and conjugation by local Cliffords.
$$^3$$ This is not obvious from the diagram and is easier to see by interpreting the diagram as a linear operator.
$$^4$$ For example, by comparing the computational basis expansions of $$|{+^{\otimes n}}\rangle+|{-^{\otimes n}}\rangle$$ and $$|{+^{\otimes n}}\rangle-|{-^{\otimes n}}\rangle$$.
$$^5$$ See e.g. this paper for more information about labeling spiders in ZX diagrams with variable names to represent measurement outcomes and classical conditioning of quantum gates.
$$^6$$ This is a simple special case of the Baker-Campbell-Hausdorff formula. It is also easy to prove using series expansion of the exponential function.

• Hello. Thank you very much for your very detailed answer. I need a bit more time to dig in the details but it seems to be the exact answer I was looking for! Commented Sep 20, 2023 at 10:10