# Controlled Hadamard gate in ZX-calculus

What is the representation of the CH gate in ZX-calculus?

Is there a general recipe for going from a ZX-calculus representation of a gate to the representation of the controlled version?

In answer to your first question, yes there is a way to build controlled-$$H$$ in ZX. It more or less mirrors the construction in quantum circuits. First, one can construct controlled-$$Z$$-phase gates using the technique described in the "Quantum Computing" chapter of mine and Coecke's book (Picturing Quantum Processes, p. 687):

n.b. the white dots are $$Z$$-spiders, gray dots are $$X$$-spiders.

This is a controlled phase gate, which conditionally applies a $$Z(\alpha)$$ on the second qubit if the first qubit is $$|1\rangle$$. Using the bialgebra law, it is not too hard to show this is actually equivalent to a more familiar "circuit-like" form of the gate:

From the controlled-$$\operatorname{Z}$$ phase gate, wrap the control bit in Hadamards to get a controlled-$$X$$ phase gate.

To create a controlled Hadamard, take its Euler decomposition to get $$Z(\pi/2) X(\pi/2) Z(\pi/2)$$, then to get the controlled version, replace each of the phase gates with controlled-phase gates.

As a general rule (and somewhat in line with Nick's answer), any "circuit-like" ZX-diagram (i.e. built out of $$\operatorname{CNOT}$$, $$H$$, and phase gates) can be transformed into the controlled version much like you can with a circuit. Phases become controlled-phases, $$H$$s becomes controlled-$$H$$s, and $$\operatorname{CNOT}$$s become Toffolis (which can also be constructed from spiders, though it's a bit more elaborate).

There is also a general technique for adding control wires to ZX-diagrams, which is explained in a recent paper by Jeandel, Perdrix, and Vilmart: arXiv:1805.05296

However, either technique tends to yields big, unwieldy diagrams. If you find you are working with controlled or multiply-controlled operations a lot, the ZH calculus (a variation on ZX which allows many-legged $$H$$-gates) could be more convenient to work with: arXiv:1805.02175.

• Thanks Aleks! Did you by and chance mean that the H gates wrap the target qubit to turn a CZ into a CX? – Daniel Mahler May 5 at 4:17

The easiest way to do this would be to use the general controlled unitary construction given in this post: Given a decomposition for a unitary $U$, how do you decompose the corresponding controlled unitary gate $C(U)$? translate the circuit to ZX and hopefully simplify the circuit using ZX rewrite rules to get a nicer expression.

If you use the symbol of triangle and lambda box in ZX, see e.g. my paper with KangFeng Ng arXiv:1706.09877, then there are two simple ways of representing the CH gate in ZX-calculus, one of them even need not any decomposition of the H gate (diagrams should be read from top to bottom):

If you don't want any H showing in CH, then you have another diagram for CH:

From my experience, translating C(U) circuits into ZX usually is not an easy way for getting nice expression even after ZX simplification, if you don't know a nicer expression in advance.

First, there is a neat way of performing the controlled Hadamard, with only two occurrences of the $$T$$ gate:

Regarding your second question, I can give an answer that will get a tad technical, based on the paper arXiv:1805.05296. We are going to use the following construction

that we generalise to $$n$$ wires:

The reason we denote this operator like this is if plug $$|0\rangle$$ on the control half-edge, we get the identity, while if we plug $$|1\rangle$$ we get $$2|+\rangle\langle+|$$.

We are given a diagram $$U:n\to n$$. The first thing we do is use the map/state duality to get a diagram $$U':0\to 2n$$

Now, suppose there exists a diagram $$\Lambda U':1\to 2n$$ such that $$\Lambda U'|0\rangle = 2^n|+^{2n}\rangle$$ and $$\Lambda U'|1\rangle = U'$$. Then the controlled version of $$U$$ can be performed by building:

The question hence boils down to finding such a $$\Lambda U'$$. A first "naive" solution is to treat the map $$U'$$ nearly as a black box: we only require you know a non-null entry of $$U'$$: $$\langle a_1...a_{2n}| U' = x \neq0$$ for some $$a_1,...,a_{2n}\in\{0,1\}^{2n}$$, and such that one can represent $$\begin{pmatrix}1\\1/x\end{pmatrix}$$ with a diagram $$\Lambda (1/x):0\to 1$$ in the fragment (in the unrestricted ZX-Calculus, this is always possible). Using yet another construction:

generalised to:

we can define $$\Lambda U'$$ as: