Quantum circuit notation is widely used in the field of quantum computing to denote computations to be executed on a quantum computer. While quantum circuits are a useful tool for representing computations on a quantum computer, they are somewhat inconvenient for reasoning about computations (such as proving equalities or doing simplifications); and for representing computations in alternative models like the one-way model of measurement-based quantum computation (MBQC) , or surface code lattice surgery .
ZX-diagrams are an alternative, more general representation of quantum computations, which allow complex operations to be described using a few simple generating operators. ZX-diagrams come with an equational theory, called the ZX-calculus , which allows one to perform many useful calculations graphically, without resorting to concrete matrix computations. While ZX-diagrams can be seen as an extension of circuits , they also readily admit encodings of the one-way model  and lattice surgery , and allow one to reason more easily about such procedures. There are several known complete axiomatisations of the ZX-calculus [35, 46], where any true equality of linear maps can be proved graphically. For a review on the ZX-calculus we refer to .
The ZX-calculus has been used in a variety of areas. It was used to optimise T-count [32, 17], braided circuits  and MBQC ; to find a new normal form for Clifford circuits ; to do more effective classical simulation using stabiliser decompositions ; and to reason about surface codes [25, 26], mixed-state quantum computations 9], condensed matter systems , counting problems [20, 41] and spin-networks .
As a strict extension of quantum circuit language, ZX-diagrams may express operations in a form that do not correspond directly to a quantum circuit. This added flexibility makes it easier to find novel strategies to simplify quantum circuits, but it comes at a cost: given a ZX-diagram representing a unitary linear map, it might be non-trivial to transform it back into a circuit of comparable size. Such a translation might however be necessary if, for instance, we want to run the computation described by a ZX-diagram on a gate-based quantum computer.
We refer to the above problem, as the circuit extraction problem: given a ZX-diagram which denotes a unitary operator , find a unitary circuit (i.e., a quantum circuit without measurements) that implements . In recent years, some progress has been made on this problem [21, 32, 4, 38, 31, 18]. However, all known methods for efficient extraction of circuits from ZX-diagrams rely on additional conditions, in particular requiring there to be some kind of flow on the diagram, a concept imported from MBQC . Such conditions allow the diagram to be rewritten incrementally into a unitary circuit. Since many ZX-calculus rewrites preserve these conditions, it is possible to perform optimisation of quantum circuits using ZX-calculus rules and still recover circuits efficiently.
However, it is worth trying to generalise these conditions as much as possible, or even remove them. For instance, it was noted in  that a certain transformation of ZX-diagrams would decrease the T-count (an important metric for quantum circuit optimisation), but in the process broke the invariant (the existence of a gflow), preventing a circuit from being extracted efficiently using known techniques. Given all this it is then natural to wonder about the following question:
Is there some efficient procedure to translate any
unitary ZX-diagram into a quantum circuit?
In this paper we present strong evidence that there is no such efficient procedure, by showing that the circuit extraction problem is #P-hard in the worst case. The complexity class #P contains for instance the problem of strong simulation of quantum circuits, and counting the number of satisfying solutions to a Boolean formula, so #P-hard problems are expected to be intractable. We prove #P-hardness by giving an encoding of Boolean formulae into unitary ZX-diagrams in such a way that extracting a polysize circuit provides a solution to the associated #SAT instance. A consequence of our result is that if there were a polynomial time algorithm for circuit extraction, then .
Alternatively, since there is an evident translation from a ZX-diagram into a quantum circuit with postselection, this result can equivalently be seen as expressing the hardness of translating a postselected circuit that is promised to be proportional to a unitary into a circuit without postselection. While intuitively this seems likely to be hard, particularly in light of Aaronson’s landmark result that 
, our hardness result seems to be quite different in nature due to the unitarity promise. In particular, the postselection does not seem to be the ‘source of power’ in our proof: the measurement outcomes corresponding to the post-selections in our circuits occur with some bounded probability, independent of the problem size.
One could ask how much our hardness result is tied to the fact that we require a procedure that produces quantum circuits from ZX-diagrams. Especially, when considering that in most cases we are not interested in the circuit itself, but instead we simply want to sample the output of the quantum computation. Perhaps one could find some other procedure to “program” a quantum computer using a ZX-diagram describing a unitary and obtain samples of measurement outcomes. We show that an efficient such procedure is unlikely to exist for arbitrary ZX-diagrams, by finding that such a procedure allows you to probabilistically solve NP-hard problems. So if there were some way to generically translate unitary ZX-diagrams into procedures which could be realised in polynomial time on a quantum computer, it would follow that the entire polynomial hierarchy is in BQP, and in particular that .
The paper is structured as follows. We start by covering preliminaries on quantum circuits, ZX-diagrams and the necessary complexity theory in Section 2. Then in Section 3 we formally define the circuit extraction problem and prove it is hard. Section 4 considers several variations on circuit extraction, and in Section 5 we find some upper bounds on the hardness of circuit extraction. We end with some concluding remarks in Section 6.
2.1 Quantum circuits
Since we wish to extract ‘a circuit’ from a ZX-diagram, it will be helpful to first consider what we actually mean by a circuit.
In quantum computational theory, a ‘circuit’ is a description of a computational process consisting of operations which may be decomposed as a sequence of primitive ‘gates’ and ‘measurements’, which act on one or more qubits to change the states of those qubits. The state-space of a qubit is identified with the finite-dimensional Hilbert space ; the state of
qubits in parallel is described by the tensor product. A ‘gate’ is an operation which is applied to one or more qubits and implements a unitary transformation on the associated state space. A ‘measurement’ is an operation which transforms a state to some state where is a set of projections that sum up to the identity operator , the gives the probability of observing that particular measurement outcome and is given by , and the index provides the classical ‘outcome’ indicating which transformation occurred. A gate or measurement acting on a small number of qubits can be applied to a larger set of qubits by taking the tensor product with an appropriate number of identity operators. A ‘circuit’ is then a composition of such gates and measurements on some number of qubits, acting in sequence or in parallel, to describe more complex (and in general, non-deterministic and irreversible) transformations of a quantum state-space. For the purposes of using quantum circuits to define a reasonable model of computation, one usually elaborates the above with a description of how one would specify a circuit as part of a family of unitary operators, acting on inputs of various sizes (see Appendix A for details). For our purposes, it will suffice to require that the coefficients of the gates be efficiently computable, and in particular provided explicitly in some representation which suffices to approximate them to bits of precision in time for an qubit circuit.
It will be convenient to refer to one specific such gate-set — an infinite set of gates, consisting of the single-qubit gates for arbitrary angles , the single-qubit Hadamard gate and the two-qubit gate CNOT:
This gate set forms a universal gate set, meaning that a unitary acting on any number of qubits can be written as a circuit consisting of these gates . Other universal gate-sets exist, but so long as one considers gate sets whose parameters are efficiently computable from some input parameters and which act only on a bounded numbers of qubits (e.g., at most two or three qubits), the size of a circuit to represent a given unitary operator can only vary by a constant factor, so that for the purpose of complexity theory, the details of the specific gate set chosen are not important.
A circuit which contains no measurements, and therefore consists entirely of unitary gates, is called a ‘unitary circuit’. A unitary circuit is reversible, and ‘deterministic’ in the sense that an idealised realisation of such a circuit will transform the state-space in the same way each time. As this is a convenient feature for the design and analysis of quantum algorithms, much of the literature on quantum algorithms concerns itself with unitary circuits, and much of the design of quantum computers is concerned with how to reliably implement unitary circuits.
ZX-diagrams form a diagrammatic language similar to the familiar quantum circuit notation. A ZX-diagram (or simply diagram) consists of wires and spiders. Wires entering the diagram from the left are inputs; wires exiting to the right are outputs. Given two diagrams we can compose them by joining the outputs of the first to the inputs of the second, or form their tensor product by simply stacking the two diagrams [10, 11].
Spiders are linear operations which can have any number of input or output wires. There are two varieties: -spiders depicted as green dots and -spiders depicted as red dots:
Note that if you are reading this document in monochrome or otherwise have difficulty distinguishing green and red, spiders will appear lightly-shaded and darkly-shaded. The diagram as a whole corresponds to a linear map built from the spiders (and permutations) by the usual composition and tensor product of linear maps. As a special case, diagrams with no inputs represent (super-normalised) state preparations. Note that when , we will not write the phase on the spider.
We can immediately write down some simple state preparations and unitaries in the ZX-calculus:
We can also represent the effects that are dual to the states above using spiders:
In the diagrams above we write explicit scalars to represent a proportionality constant. In this paper (non-zero) scalar factors will not be important. However, do note it is always possible to represent any scalar as an explicit ZX-diagram (of constant size). For this reason, our results will also apply to other proposed normalisations of the ZX generators, such as those in Refs. [16, 13, 23].
It is often convenient to introduce a symbol — a yellow square — for the Hadamard gate. This is defined by the equation:
The CNOT gate also has a straightforward representation as a ZX-diagram:
Seeing as can represent , and CNOT gates as ZX-diagrams, we see that we can in fact represent any unitary as a ZX-diagram. The above demonstrates that ZX-diagrams can be used as an alternative representation for quantum circuits. However, ZX-diagrams are also more versatile than unitary circuits. Consider for example the following construction of the CZ gate as a ZX-diagram:
The right-hand-side demonstrates a different diagrammatic construction for CZ, that does not immediately look circuit-like, with the Hadamard-box representing some sort of interaction of two qubits rather than the evolution of a single qubit.
In fact, this versatility is reflected in the property that ZX-diagrams are universal for all linear maps between any number of qubits. To see this, note that we can represent states as in Eq. (3). By composing tensor products of these states with some unitary we can write down any quantum state. By the map-state duality of quantum theory (i.e. the Choi-Jamiołkowski isomorphism), we can then also write every linear map, see for instance  for the details.
The universality of the gate-set and of the ZX-calculus means that any unitary operator on some fixed number of qubits may be represented by some ‘gadget’ in the ZX calculus, consisting of some fixed diagram of finite size — though as the example of CZ in Eq. (7) shows, there may also be ‘gadgets’ which represent a unitary operator which do not consist of sequential and parallel composition of diagrams from Eq. (2). Indeed, even the representation of the CNOT is by a simple ‘gadget’ of two nodes, which is not describable as a composition of the other single-node ‘gadgets’. In this respect, ZX-diagrams represent a more versatile notation than a conventional circuit notation. This raises the question of how, given a representation of some unitary as a ZX-diagram, one might find another representation of which consists of just compositions from the universal gate-set . This is the problem that this paper is concerned with.
ZX-diagrams are more than just a notation for unitary circuits (and non-unitary operators more generally): they may be used to perform computations. Specifically, ZX-diagrams come with a set of graphical rewrite rules, which may be used to find equivalent diagrams which represent the same state or operator, just as one might manipulate an algebraic expression. This rewrite system is complete [35, 46]: unlike other circuit diagrams, one may show that two equivalent ZX-diagrams are equivalent though transformations of diagrams alone. The possible advantage of this is that ZX-diagrams can often concisely represent operators which have a very large number of non-zero coefficients, and so that this reasoning can be done efficiently while it could not be done using the matrices directly. For instance, one of the rewrite rules we will use in this paper is spider fusion:
These rules say that we can fuse together adjacent spiders of the same colour.
While these rewrite rules are not immediately relevant to our results, the fact that it is possible to compute with ZX-diagrams is the motivation for considering this particular representation of unitary circuits, and also motivates the concept of considering different ZX-diagrams which represent the same unitary transformation. We refer the interested reader to  for an overview.
2.3 Circuit extraction
In the above section we saw that we can get ZX-diagrams directly from quantum circuits. We can also get ZX-diagrams from considering measurement patterns in the one-way model . In the one-way model of quantum computation we start with a large graph state, on which we then do subsequent measurements, where the choice of measurement angle and axis may depend on previous measurement outcomes. This leads to another universal model of quantum computation. The one-way model can be straightforwardly represented in the ZX-calculus [22, 4].
An important property of a one-way computation is that we can perform a computation deterministically, so that we perform the same overall computation regardless of individual measurement outcomes. A sufficient property for ensuring that deterministic processes are possible on a given resource state is that its underlying graph has a property known as gflow . This is an efficiently verifiable combinatorial condition on the entangled resource.
When we represent a one-way computation with gflow as a ZX-diagram, the gflow ensures that certain ‘local’ parts of the diagram correspond to individual unitary gates, in a way which can be iteratively translated into an actual unitary circuit. In this case we can hence extract a unitary quantum circuit from the ZX-diagram that represents the one-way computation. See for instance [21, 4, 38] for several variations on this idea.
Measurement-based quantum computation like the one-way model is a type of non-unitary quantum computation. Another type of non-unitary model is given by doing lattice surgery in the surface code [29, 19]. A lattice surgery procedure can also be represented as a ZX-diagram . Just as in the one-way model, there is a flow condition that ensures such a calculation is deterministic, and that the resulting ZX-diagram can be step-by-step rewritten into a unitary circuit .
We see that there are several quantum computational models that can be written in terms of ZX-diagrams, which can be rewritten into a unitary quantum circuit efficiently when they satisfy some condition. The type of flow condition required for these procedures ensures that the diagram can’t get ‘too wild’ in the middle, so that we can stepwise rewrite the diagram into something that looks more like a circuit. A natural question to ask then is how much we can weaken such additional conditions, and in particular if we can transform a ZX-diagram into a circuit efficiently in the most general setting, where the only condition we require of the ZX-diagram is that it is proportional to a unitary. The main result of this paper is that such a general efficient procedure most likely does not exist.
2.4 Background on computational complexity
Finally, we provide some background on computational complexity. We assume knowledge of P, the boolean satisfiability problem , oracle machines, NP
and nondeterministic Turing machines (NTMs) in general. Our results concernCook reductions (in fact, usually Cook reductions). A Cook reduction from a problem to another problem is an algorithm for solving using a deterministic Turing machine which halts in polynomial time, but which may query an oracle (in the case of a Cook reduction, exactly once) for . This implies that, modulo some polynomial-time computation, the problem is at least as hard as ; and that if , we also have . In symbols we may write . Our results will generally concern problems related to ZX-diagrams and problems which are at least NP-hard (i.e., they suffice to solve ).
Quantum circuits (specifically: uniform circuit families, as described in Appendix A) form a model of computation, which may be considered to generate random outcomes through measurement operations. The class BQP consists of decision problems which can be decided with bounded error (with error probability less than , say) by such circuit families, and represents the decision problems that can be practically solved by an (idealised) quantum computer. It is not expected that either of NP or BQP contain the other. So if we can reduce in polynomial time (by many-to-one or oracle reductions) an NP-complete problem to some problem , then we expect to be intractable for quantum computers. Certain modifications of the quantum computational model do allow for more difficult problems to be solved, however. For instance, PostBQP is the class of problems which may be solved with bounded error by a uniform quantum circuit family, conditioned on some other measurement yielding a specific outcome (which occurs with non-zero probability). This ‘conditioning’ restriction is known as postselection, and appears to be operationally very powerful, as PostBQP coincides with the class PP, of decision problems for which a ‘yes’ instance is accepted on more than half of the branches of some NTM halting in polynomial time.
The class P is closed under oracles: a deterministic Turing machine equipped with an oracle for some problem in P cannot decide more problems in polynomial time than a normal Turing machine, so that . The same is true for BQP: any decision problem solvable (with bounded error) by a uniform family of quantum circuits, can also be solved (with bounded error) by some other family of quantum circuits without oracle access, so that . The same is not true, however, for NP: it is not known whether (the class of decision problems, for which there is an NTM with an oracle for a problem in NP, halts in polynomial time and accepts in some branch precisely for ‘yes’ instances) is equal to NP. It is widely conjectured that , and indeed that , and so forth. The union of for all , defines the class PH, called the polynomial hierarchy .
The hardness results which we are most concerned with involve problems in #P: the class of problems which may be reduced to counting the number of accepting branches of some NTM on a given input. In particular, we are interested in the problem #SAT, of counting the number of ‘solutions’ to an instance of SAT, presented as a formula for a function , where a ‘solution’ satisfies . The problem #SAT is #P-complete , as is tensor contraction over the natural numbers , and ‘strong simulation’ (i.e.
, precise estimation of explicit measurement probabilities) of uniform quantum circuit families. The #P-completeness here means that a Cook reduction from any of these problems to some problem , establishes that there is a Cook reduction from any problem to . in this case we say then that is “#P-hard”. The computational power of #P is considered to be significantly greater than that of NP. In particular, Toda  showed that .
3 Proof of hardness of Circuit extraction
We now present the central problem of our work.
Input: A ZX-diagram with inputs and outputs and at most wires and/or spiders, and a set of unitary gates (each acting on at most qubits).
Promise: The operator denoted by is proportional to a unitary.
Output: Either (a) a -size circuit , expressed as a sequence of gates from and expressing an -qubit unitary that is proportional to the operator denoted by , if such a circuit exists; or (b) a message that no such circuit exists, if that is the case.
Note that here we make no assumptions on the specific gate set , apart from the computability of the coefficients as described in Section 2.1, and that the number of qubits which is bounded by some constant. One might object to the requirement that the output list of gates must be polynomially related to the size of the input ZX-diagram: however, as we are interested in whether the extraction problem can be solved efficiently, the restriction on the size of follows from the time required to represent it as a list of gates.
The above problem can of course also be stated for any related graphical language for quantum operations, such as the ZH-calculus  or the ZW-calculus . Since such diagrams can be efficiently translated into one another, these problems are of equivalent hardness. There are some other reasonable variations we can consider of CircuitExtraction that we will discuss in the next section.
We will now show that CircuitExtraction is #P-hard. We do this by building a diagram that is proportional to a unitary based on a SAT instance, and showing that the resulting matrix the diagram represents is uniquely determined by the number of solutions of the instance.
Let be a Boolean formula with terms. We say a bit string is a solution to when . The first step will be to build a ZX-diagram that implements the linear map that takes qubits to qubit by . We can of course represent as a tree of AND and NOT operations so that to construct it suffices to find linear maps that implement AND and NOT on .
We may consider ZX diagrams for “quantum” versions of the boolean logical AND gate and NOT gate, i.e., linear operators such that , , and . These operations can be represented (up to a constant factor) by the following ZX-diagrams:
The NOT gate is just an gate, but the AND is more complicated. It is based on the 4 -gate representation of the CCZ gate from .
By combining these diagrammatic gadgets for NOT and AND we can build the operation as a ZX-diagram using spiders. Now, note that:
where is the number of solutions of , is the number of ‘non-solutions’ of , and we set and for . The resulting state is not normalised: to normalise it we should multiply both sides by .
We use the ‘state’ described in Eq. (8) as the input of a controlled operation. By choosing the controlled operation appropriately, we will be left with something proportional to a unitary. We may for instance consider the following diagram:
To see this is unitary first recall that a rotation over an angle applied to gives . Hence the state of Eq. (8), when properly normalised, can be written as for . We can then calculate:
In the above, we use the relation , and some simple ZX-calculus rewrites. Hence, the diagram of Eq. (9) is proportional to an rotation where is uniquely determined by the number of solutions to . Note that this operation can be easily represented (with at most three gates) using a gate-set such as , in which the set of values of allowed angles include those that may arise in the diagram of Eq. (10) for some number of solutions to the formula ; such an operation will be representable using other gate-sets as well.111Note that the gate-set described here cannot be a single, finite gate set for all values of . However, the angles arising out of instances of satisfiability in this way can be specified in bits, precisely by characterising them in the way that we have as being related to some integer ranging in via inverse trigonometric functions. For remarks on what can be achieved with finite gate-sets, the reader may be interested in our remarks on the related problem ApproxCircuitExtraction, in Section 4.
CircuitExtraction is #P-hard.
#SAT is a #P-complete problem, so it suffices to show that we can count the number of solutions to a Boolean formula using a call to an oracle which solves CircuitExtraction. Given a Boolean formula with terms, construct the diagram of Eq. (9). The diagram here for uses of the diagrammatic gadgets for NOT and AND, and hence the complete diagram consists of spiders, each of which may be restricted to having at most wires. We may apply the CircuitExtraction oracle on this diagram subject to a suitable gate set that can exactly generate the possible X-rotations which may arise. As is a single-qubit circuit with at most gates, we can calculate the unitary it implements, up to any required precision , in polynomial time. We know that the operation realised is of the form , so to determine the value of , it suffices to estimate the entries of the resulting to within an error of . Determining the value of to bits of precision is more than sufficient to do this. ∎
If there is a polynomial time algorithm for CircuitExtraction, then . In particular, the polynomial hierarchy collapses to the first level: .
If CircuitExtraction can be done in polynomial time, then the above shows that we can solve #SAT in polynomial time, and hence . ∎
Our construction of the diagram we use to prove our result might seem somewhat arbitrary. To motivate it some more, first realise that instead of the function , we could have used the standard unitary quantum oracle for a Boolean function which acts on qubits via . We can get out of by post-selecting the top qubits to . Using the language of post-selection, we may then present a circuit version of Eq. (9):
The top part is calculating the number of solutions, while the bottom part ensures that this information is fed into a qubit in such a way that the overall operation is proportional to a unitary. The choice of is for the sake of simplicity: any unitary that satisfies would also suffice, such as or .
Even though we can view the diagram as a post-selected circuit, this does not seem to be where the power of the procedure comes from, as it is for instance in Aaronson’s  characterisation PostBQP = PP. The probability of observing the ‘correct’ outcome is bounded from below by a constant, and does not depend on . This means in particular that by doing repeat-until-success we could with high probability implement the circuit Eq. (11) on a quantum computer. However, this does not allow you to solve #SAT, as adjacent possibilities of the rotation angle are exponentially close. So rather, the power of the procedure comes from getting an explicit description of the circuit which allows us to exactly calculate the rotation angle.
4 Variations on extraction
There are several variations on circuit extraction which we can consider, all of which also turn out to be hard.
The essential trick we used in our proof is that our resulting circuit has just one qubit, and hence a description of a unitary on it can easily be transformed into the actual unitary it implements by just multiplying all the resulting matrices. But of course the same statement remains true if we have slightly more than one qubit, say a logarithmic amount in the size of the SAT instance. We also see that it then doesn’t matter if our circuit contains auxiliary qubits, measurements, or classically-controlled corrections. All of these can be efficiently calculated as long as the number of qubits is small enough. Therefore, let’s define the following variant of circuit extraction.
Input: A ZX-diagram with inputs and outputs and at most wires and/or spiders, and a set of unitary gates (each acting on at most qubits).
Promise: The operator denoted by is proportional to a unitary.
Output: Either (a) a deterministic -qubit circuit implementing the unitary of the input ZX-diagram, described as a length list of gates, auxiliary qubit preparations, measurements, and classical corrections, with at most auxiliary qubits; or (b) a message that no such circuit exists, if that is the case.
AuxCircuitExtraction is #P-hard.
We construct the same diagram as in the proof of Theorem 3 to solve a #SAT instance, except that we can no longer assume that the final circuit will act only on a single qubit: instead it may act on up to qubits, including the operations on the auxiliary qubits. The size of the matrices involved when trying to calculate the resulting unitary is , where here is the size of the input diagram. We may then still multiply the matrices together in polynomial time to obtain sufficiently precise estimates of the coefficients. ∎
One might also object that requiring the output unitary to exactly represent the ZX-diagram is too strong — in particular, impossible in general even with an approximately universal, finite gate set — and wish for an approximate output instead. We say that a unitary operator is an -approximation of another unitary for some , if for some global phase . Here, denotes the operator norm of
: the largest singular value of.
Input: A ZX-diagram with inputs and outputs and at most wires and/or spiders, a set of unitary gates (each acting on at most qubits), and a precision parameter .
Promise: The operator denoted by is proportional to a unitary.
Output: Either (a) a -size circuit , expressed as a sequence of gates from and expressing an -qubit unitary which is an -approximation to either the operator denoted by , or some operator proportional to it; or (b) a message that no such circuit exists, if that is the case.
ApproxCircuitExtraction is #P-hard.
For a given SAT instance we again construct the same diagram as in the proof of Theorem 3 which denotes a unitary , where allows us to determine the number of solutions to . This diagram has spiders. Set for some large enough constant . Then applying ApproxCircuitExtraction gives rise to a circuit, which has gates. We can hence just multiply out the matrices in order to determine the unitary it implements. This unitary approximates to degree . Since the top left entry of is real, we can first multiply by the appropriate global phase to ensure it is also real. If we have picked large enough then the entries of are then within of that of so that we can determine by rounding to the nearest allowed value. ∎
Note that, even for exponentially small angles as might arise when has few solutions, circuits of polynomial size do exist for when is an approximately universal gate-set: using the Solovay–Kitaev algorithm [34, 15] or any of its many refinements (see e.g. Ref.  and references therein), we may synthesise circuits approximating to any precision in time scaling polynomially in . The difficulty of ApproxCircuitExtraction stems from determining which angle to approximate.
Let us consider one final variation on extraction. One could argue that the reason that we end up with a hard problem in these instances, is because requiring the output to be some kind of circuit is too restrictive. The ultimate goal of circuit extraction is that we wish for the ZX-diagram to be run on a quantum computer, to obtain some probability distribution over outcomes; but the complexity ofCircuitExtraction and its variations seems to arise from the complexity of finding a precise description of the procedure to do so. Cutting out the middle-man, we may consider any process which takes as input a unitary ZX-diagram, and produces bit strings as output whose distribution conforms with the one we expect from the unitary.
Input: A ZX-diagram with inputs and outputs and at most wires and/or spiders.
Promise: The operator denoted by is proportional to some unitary .
Output: A sample from a probability distribution, given by (or sufficiently close to) .
It is clear that UnitaryZXSampling is at least as hard as BQP: we could just input a ZX-diagram that directly represents a quantum circuit, in which case this problem is equivalent to simulating that circuit. The reason we write here that the probabilities just have to be ‘sufficiently close’ is because the exact number doesn’t matter for the theorem below. To be concrete we could for instance allow the probability to additively deviate by from the true value.
There is a randomised polynomial reduction from NP to UnitaryZXSampling. In other words: with access to a PromiseUnitaryZXSampling oracle—which produces the expected output if the input diagram is unitary and arbitrary output otherwise—we can with high probability solve NP-complete problems.
SAT is an NP-complete problem. To randomly reduce NP it however suffices to consider the problem USAT by the Valiant–Vazirani theorem . USAT asks us to determine whether a Boolean formula is satisfiable, given the promise that it has at most one solution. Using the randomised reduction from SAT to USAT, we consider how to solve USAT using a PromiseUnitaryZXSampling oracle.
Let be a Boolean formula that has at most one solution. Construct the diagram Eq. (9) as in the previous proofs: as a unitary this implements the identity iff is not satisfiable, and for some fixed angle when is satisfiable. In the latter case, the value of is exponentially small, but known precisely, as has exactly one solution in this case. So we can say the circuit implements where encodes whether is satisfiable or not.
be the one-qubit (non-unitary) matrix that mapsand , so that in particular . By universality of ZX-diagrams we can find some (constant sized) diagram to represent . We can then calculate:
Hence, the ZX-diagram on the left in Eq. (12) implements either the identity, or an operation (that is to say, a NOT operation), depending on whether is satisfiable. When we feed this ZX-diagram to an oracle for PromiseUnitaryZXSampling, we get either the output 0 or 1, where a 0 indicates with high probability that the circuit is the identity, and a 1 indicates that the circuit is a NOT operation. We can repeatedly call the oracle to get additional samples to increase our confidence in the result.
Now suppose is a general instance of , which may have more than one solution. Using the Valiant–Vazirani reduction multiple times we probabilistically produce different Boolean formulae . If is not satisfiable, then none of the will be satisfiable either and this is what the PromiseUnitaryZXSampling will tell us as well. If is satisfiable, then a significant fraction of the will have a unique solution, so that our oracle tells us they are satisfiable. For the other the oracle will return some arbitrary output. So by picking large enough there will with high probability be some that will be uniquely satisfiable, and so we can conclude that is satisfiable as well.
Hence, we can determine with arbitrary high probability whether a SAT instance is satisfiable using enough calls to PromiseUnitaryZXSampling. ∎
If we knew that the number of solutions to the SAT instance was some other fixed number, then we could pick a different matrix to boost the state up to gate as above. If we pick ‘slightly wrong’, then the resulting diagram will just be close to . One might think that we could use such a procedure to try and determine the number of solutions to by doing binary search on the number of solutions, and so boost the power of UnitaryZXSampling to #P. However, the problem with this is that the resulting diagrams are not proportional to a unitary most of the time. There might be some way around this issue, so that UnitaryZXSampling is still #P-hard: we leave this as an open problem.
Note that if we were to consider a version of UnitaryZXSampling, without the promise of unitarity, such an oracle would be as powerful as PostBQP, since we can represent any ZX-diagram as a post-selected quantum circuit. In our case, the power again comes not so much from postselection, as being able to take advantage of the versatility of ZX-diagrams to gain access, in some way, to extract very precise information regarding a #P problem.
5 Upper bounding the complexity of CircuitExtraction
Given that CircuitExtraction is #P-hard, one might ask whether or not the problem is #P-complete (or more precisely: -complete), in the sense that a Turing machine with access to a #P oracle would be able to solve it, for some given polynomial upper bound on circuit size and some given gate-set (perhaps with suitable restrictions), in polynomial time. We have not managed to prove such a completeness result. We will however present the following upper bounds on decision problem versions of circuit extraction, relying on techniques from  (which we describe in Appendix B).
First, consider the following decision problem: given a ZX-diagram, and a circuit, determine whether the circuit implements a unitary which is proportional to that represented by the ZX-diagram (whether by a factor of for some angle , or a more general complex number).
The complement of this problem is in .
To sketch why this is, consider a circuit representing a unitary , and a ZX diagram representing an operator .
If and are two non-zero coefficients from , and and are the corresponding (non-zero) pair of coefficients from the matrix represented by , then only if either for all possible such pairs.
(We compare pairs instead of single coefficients, to deal with the fact that they might only represent the same matrix up to some non-zero scalar.)
We also require that for any coefficient in which is zero, the corresponding coefficient of is also zero.
Taken together, this implies that for all corresponding pairs of coefficients of and , .
A #P oracle allows one to calculate coefficients222In this case, it is not necessary to compute complete information about , , , and : it suffices to compute information about individual components of the products and , where these are regarded as vectors over
, where these are regarded as vectors over. (See the closing remarks of Appendix B.) of ZX-diagrams and circuits: if , an NTM with access to a #P oracle can non-deterministically find a witness that these two operators are not in fact proportional to one another. Thus, determining whether a circuit does not represent a unitary which is denoted (up to scalar factors) by a ZX-diagram, is in .
The above result has a simple corollary: the property of a ZX-diagram being proportional to a unitary, itself belongs to the complement of . We may see this by the fact that a ZX-diagram denoting an operator , which is proportional to a unitary, satisfies . We may represent by composing the diagram with its adjoint (which is the left-to-right mirror image of , with all phase angles negated). This composite diagram may easily be computed, at which point we may ask whether the operator it represents is distinct from the identity (even modulo non-zero scalar factors). As we note above, this problem is in .
Finally, using these ideas, we may consider the decision problem of determining, for a ZX-diagram which denotes an operator proportional to a unitary, and given some (approximately universal) gate set and polynomial length bound , whether there exists a circuit of at most gates over which implements . This problem is in : for an NTM with access to an oracle, it suffices to make a nondeterministic guess at a circuit of length (where each gate may be the identity operator, or some gate acting on a non-deterministically chosen set of qubits) and then query the oracle to determine whether the circuit approximately realises . A deterministic Turing machine, with access to an oracle for this problem, could then solve ApproxCircuitExtraction in polynomial time using standard techniques, using the oracle to facilitate a search for a circuit to realise .
These observations represent the most straightforward approach to determining an upper bound for the circuit extraction problem, and seem to place it at a level of complexity significantly higher than . If we conceive of #P as broadly representing the complexity of evaluating a tensor network, a superficial analogy between CircuitExtraction and boolean circuit minimisation [24, 7] would seem to suggest that CircuitExtraction is likely to be hard for some complexity class higher than (barring some collapse of complexity classes).
In this paper we studied the problem of extracting a quantum circuit description from a unitary ZX-diagram. We’ve shown that this problem is #P-hard by reducing #SAT to an application of circuit extraction. We’ve also studied some variations where we allow auxiliary qubits, classical control, and/or approximate synthesis of the desired unitary, and have shown that these problems are also #P-hard. In addition, we studied the hardness of a machine that takes in a unitary ZX-diagram and outputs measurement samples from that ZX-diagram, and have shown that such a machine allows one to probabilistically solve NP-hard problems.
A conclusion to be drawn from our results is that if we want some efficient procedure to transform a unitary ZX-diagram into a quantum circuit, then we will have to have some additional information about the structure of the ZX-diagram. In the known procedures for efficient circuit extraction [4, 38, 18], this additional information takes the form of a kind of ‘flow’ on the diagram that prevents parts of the diagram from becoming too unwieldy. An immediate question then is if there are other types of, more general, promises on the structure of the diagram which then allow you to extract a circuit from it.
Aaronson showed that sampling from a post-selected quantum circuit is hard . Our results imply that some other tasks surrounding unitary post-selected circuits (that is, circuits which perform a unitary transformation conditioned on some post-selection) are hard. However, this hardness seems to stem not from the post-selection itself, as the post-selections can be simulated with high probability in our case. Rather, the hardness seems to stem from a hypothetical ability to find an equivalent, deterministic way to realise the same operation — which implies an ability to extract difficult-to-access information about the input diagram.
A question related to circuit extraction from ZX-diagrams is circuit extraction from deterministic measurement patterns (in for instance the one-way model or lattice surgery). When we have a deterministic measurement pattern, we can represent each branch of the computation by a ZX-diagram denoting a unitary. Our hardness proof does however not immediately translate to this setting, as it might be that the fact that all of these ZX-diagrams are branches of the same measurement pattern forces some kind of structure on the diagrams that might make it easier to rewrite them into circuits. The diagrams we used to show hardness of circuit extraction are as far as we are aware not representable as branches of some deterministic measurement pattern, so that we can’t use the same proof. We leave it for future work to determine the hardness of extracting unitary circuits from deterministic measurement patterns.
Acknowledgements.JvdW is supported by an NWO Rubicon personal fellowship.
-  Scott Aaronson. Quantum computing, postselection, and probabilistic polynomial-time. Proceedings of the Royal Society A: Mathematical, Physical and Engineering Sciences, 461(2063):3473–3482, 2005. doi:10.1098/rspa.2005.1546.
-  Leornard M. Adleman, Jonathan DeMarrais, and Ming-Deh A. Huang. Quantum computability. SIAM Journal on Computing, 26:1524–1540, 1997.
-  Miriam Backens and Aleks Kissinger. ZH: A complete graphical calculus for quantum computations involving classical non-linearity. In Peter Selinger and Giulio Chiribella, editors, Proceedings of the 15th International Conference on Quantum Physics and Logic, Halifax, Canada, 3-7th June 2018, volume 287 of Electronic Proceedings in Theoretical Computer Science, pages 18–34. Open Publishing Association, 2019. doi:10.4204/EPTCS.287.2.
-  Miriam Backens, Hector Miller-Bakewell, Giovanni de Felice, Leo Lobski, and John van de Wetering. There and back again: A circuit extraction tale. Quantum, 5:421, 3 2021. doi:10.22331/q-2021-03-25-421.
-  Adam Bouland and Tudor Giurgica-Tiron. Efficient universal quantum compilation: An inverse-free Solovay–Kitaev algorithm. arXiv preprint arXiv:2112.02040, 2021.
-  Daniel E. Browne, Elham Kashefi, Mehdi Mhalla, and Simon Perdrix. Generalized flow and determinism in measurement-based quantum computation. New Journal of Physics, 9(8):250, 2007. doi:10.1088/1367-2630/9/8/250.
-  David Buchfuhrer and Christopher Umans. The complexity of boolean formula minimization. Journal of Computer and System Sciences, 77(1):142–153, 2011. Celebrating Karp’s Kyoto Prize. URL: https://www.sciencedirect.com/science/article/pii/S0022000010000954, doi:https://doi.org/10.1016/j.jcss.2010.06.011.
-  Titouan Carette, Emmanuel Jeandel, Simon Perdrix, and Renaud Vilmart. Completeness of Graphical Languages for Mixed States Quantum Mechanics. In Christel Baier, Ioannis Chatzigiannakis, Paola Flocchini, and Stefano Leonardi, editors, 46th International Colloquium on Automata, Languages, and Programming (ICALP 2019), volume 132 of Leibniz International Proceedings in Informatics (LIPIcs), pages 108:1–108:15, Dagstuhl, Germany, 2019. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik. doi:10.4230/LIPIcs.ICALP.2019.108.
-  Bob Coecke, Giovanni de Felice, Konstantinos Meichanetzidis, and Alexis Toumi. Foundations for Near-Term Quantum Natural Language Processing. arXiv preprint arXiv:2012.03755, 2020.
-  Bob Coecke and Ross Duncan. Interacting quantum observables. In Proceedings of the 37th International Colloquium on Automata, Languages and Programming (ICALP), Lecture Notes in Computer Science, 2008. doi:10.1007/978-3-540-70583-3_25.
-  Bob Coecke and Ross Duncan. Interacting quantum observables: categorical algebra and diagrammatics. New Journal of Physics, 13:043016, 2011. doi:10.1088/1367-2630/13/4/043016.
-  Bob Coecke and Aleks Kissinger. Picturing Quantum Processes. Cambridge University Press, 2017. doi:10.1017/9781316219317.
-  Richard D. P. East, John van de Wetering, Nicholas Chancellor, and Adolfo G. Grushin. AKLT-states as ZX-diagrams: diagrammatic reasoning for quantum states. PRX Quantum, 3:010302, Jan 2022. doi:10.1103/PRXQuantum.3.010302.
-  Carsten Damm, Markus Holzer, and Pierre McKenzie. The complexity of tensor calculus. Computational Complexity, 11(1):54–89, 2002. doi:10.1007/s00037-000-0170-4.
-  Christopher M. Dawson and Michael A. Nielsen. The solovay-kitaev algorithm. arXiv preprint arXiv:quant-ph/0505030, 2005.
-  Niel de Beaudrap. Well-tempered ZX and ZH Calculi. In Benoît Valiron, Shane Mansfield, Pablo Arrighi, and Prakash Panangaden, editors, Proceedings 17th International Conference on Quantum Physics and Logic, Paris, France, June 2 - 6, 2020, volume 340 of Electronic Proceedings in Theoretical Computer Science, pages 13–45. Open Publishing Association, 2021. doi:10.4204/EPTCS.340.2.
-  Niel de Beaudrap, Xiaoning Bian, and Quanlong Wang. Techniques to reduce -parity phase circuits, motivated by the ZX calculus. arXiv preprint arXiv:1911.09039, 2019.
-  Niel de Beaudrap, Ross Duncan, Dominic Horsman, and Simon Perdrix. Pauli Fusion: a Computational Model to Realise Quantum Transformations from ZX Terms. In Bob Coecke and Matthew Leifer, editors, Proceedings 16th International Conference on Quantum Physics and Logic, Chapman University, Orange, CA, USA., 10-14 June 2019, volume 318 of Electronic Proceedings in Theoretical Computer Science, pages 85–105. Open Publishing Association, 2020. doi:10.4204/EPTCS.318.6.
-  Niel de Beaudrap and Dominic Horsman. The ZX calculus is a language for surface code lattice surgery. Quantum, 4, 2020. doi:10.22331/q-2020-01-09-218.
-  Niel de Beaudrap, Aleks Kissinger, and Konstantinos Meichanetzidis. Tensor Network Rewriting Strategies for Satisfiability and Counting. In Benoît Valiron, Shane Mansfield, Pablo Arrighi, and Prakash Panangaden, editors, Proceedings 17th International Conference on Quantum Physics and Logic, Paris, France, June 2 - 6, 2020, volume 340 of Electronic Proceedings in Theoretical Computer Science, pages 46–59. Open Publishing Association, 2021. doi:10.4204/EPTCS.340.3.
-  Ross Duncan, Aleks Kissinger, Simon Perdrix, and John van de Wetering. Graph-theoretic Simplification of Quantum Circuits with the ZX-calculus. Quantum, 4:279, 6 2020. doi:10.22331/q-2020-06-04-279.
-  Ross Duncan and Simon Perdrix. Rewriting Measurement-Based Quantum Computations with Generalised Flow. In Proceedings of ICALP, Lecture Notes in Computer Science, pages 285–296. Springer, 2010. doi:10.1007/978-3-642-14162-1_24.
-  Richard D. P. East, Pierre Martin-Dussaud, and John van de Wetering. Spin-networks in the ZX-calculus. arXiv preprint arXiv:2111.03114, 2021.
-  Michael R Garey and David S Johnson. Computers and intractability, volume 174. freeman San Francisco, 1979.
-  Craig Gidney and Austin G. Fowler. Efficient magic state factories with a catalyzed to transformation. Quantum, 3:135, 4 2019. doi:10.22331/q-2019-04-30-135.
-  Craig Gidney and Austin G. Fowler. Flexible layout of surface code computations using AutoCCZ states. arXiv preprint arXiv:1905.08916, 2019.
-  Amar Hadzihasanovic. A diagrammatic axiomatisation for qubit entanglement. In 2015 30th Annual ACM/IEEE Symposium on Logic in Computer Science, pages 573–584. IEEE, 2015. doi:10.1109/LICS.2015.59.
-  Michael Hanks, Marta P. Estarellas, William J. Munro, and Kae Nemoto. Effective Compression of Quantum Braided Circuits Aided by ZX-Calculus. Physical Review X, 10:041030, 2020. doi:10.1103/PhysRevX.10.041030.
-  C. Horsman. Quantum picturalism for topological cluster-state computing. New Journal of Physics, 13(9):095011, 2011. doi:10.1088/1367-2630/13/9/095011.
-  C. Horsman, Austin G. Fowler, Simon Devitt, and Rodney Van Meter. Surface code quantum computing by lattice surgery. New Journal of Physics, 14:123011, 2012. Preprint at [arxiv.org/abs/1111.4022].
-  Aleks Kissinger and Arianne Meijer-van de Griend. CNOT circuit extraction for topologically-constrained quantum memories. Quantum Information and Computation, 20:581–596, 2020. doi:10.26421/QIC20.7-8.
-  Aleks Kissinger and John van de Wetering. Reducing the number of non-Clifford gates in quantum circuits. Physical Review A, 102:022406, 8 2020. doi:10.1103/PhysRevA.102.022406.
-  Aleks Kissinger and John van de Wetering. Simulating quantum circuits with zx-calculus reduced stabiliser decompositions, 2021. arXiv:2109.01076.
-  Alexei Y. Kitaev. Quantum computations: algorithms and error correction. Russian Mathematical Surveys, 52(6):1191–1249, 1997.
-  Kang Feng Ng and Quanlong Wang. A universal completion of the ZX-calculus. Preprint, 2017. arXiv:1706.09877.
-  M. A. Nielsen and Isaac L. Chuang. Quantum computation and quantum information. Cambridge university press, 2010. doi:10.1119/1.1463744.
-  Robert Raussendorf and Hans J. Briegel. A One-Way Quantum Computer. Physical Review Letters, 86:5188–5191, 5 2001. doi:10.1103/PhysRevLett.86.5188.
-  Will Simmons. Relating Measurement Patterns to Circuits via Pauli Flow. In Chris Heunen and Miriam Backens, editors, Proceedings 18th International Conference on Quantum Physics and Logic, Gdansk, Poland, and online, 7-11 June 2021, volume 343 of Electronic Proceedings in Theoretical Computer Science, pages 50–101. Open Publishing Association, 2021. doi:10.4204/EPTCS.343.4.
-  Larry J. Stockmeyer. The polynomial-time hierarchy. Theoretical Computer Science, 3:1–22, 1977. doi:10.1016/0304-3975(76)90061-X.
-  Seinosuke Toda. PP is as hard as the Polynomial-Time Hierarchy. SIAM Journal on Computing, (5):865–877, October 1991. doi:10.1137/0220053.
-  Alex Townsend-Teague and Konstantinos Meichanetzidis. Classifying Complexity with the ZX-Calculus: Jones Polynomials and Potts Partition Functions. arXiv preprint arXiv:2103.06914, 2021.
-  L G Valiant and V V Vazirani. NP is as Easy as Detecting Unique Solutions. In Proceedings of the Seventeenth Annual ACM Symposium on Theory of Computing, STOC ’85, page 458–463, New York, NY, USA, 1985. Association for Computing Machinery. doi:10.1145/22145.22196.
-  Leslie G. Valiant. The complexity of enumeration and reliability problems. SIAM Journal on Computing, 8(3):410–421, 1979. doi:10.1137/0208032.
-  John van de Wetering. ZX-calculus for the working quantum computer scientist. arXiv preprint arXiv:2012.13966, 2020.
-  Maarten Van Den Nest. Classical simulation of quantum computation, the Gottesman-Knill theorem, and slightly beyond. Quantum Information & Computation, 10(3):258–271, 2010. doi:10.5555/2011350.2011356.
-  Renaud Vilmart. A Near-Minimal Axiomatisation of ZX-Calculus for Pure Qubit Quantum Mechanics. In 2019 34th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS), pages 1–10, 2019. doi:10.1109/LICS.2019.8785765.
Appendix A Quantum circuits as a computational model
In order to describe a model of computation with bounded computational power, one usually imposes further constraints on ‘quantum circuits’, as follows.
As with the study of boolean circuits as a model of computation, one often considers a quantum circuit to be described by some polynomial-time computable procedure (a sort of ‘effective blueprint’), which for a given requires time to produce a circuit taking inputs of size . While this constraint is not essential when considering a single circuit on its own (the description of the circuit itself is a finite specification), this constraint prevents us from considering what might otherwise seem like ‘quantum algorithms’ for uncomputable problems (in the same way that one must for boolean circuits).
Furthermore, to prevent unbounded computational power from being hidden elsewhere in the description of a quantum circuit, one often imposes constraints on the gates and measurements allowed in a circuit. One common convention is to require that the unitary gates be drawn from a finite set of unitary operators, and to require that all measurements are of single qubits, with projectors . This is frequently relaxed, to permit arbitrary single-qubit operations, or Z-rotations and X-rotations by arbitrary angles, and to allow one or two particular two-qubit gates, such as CNOT or CZ, and single-qubit measurements in an arbitrary basis; one then requires that the parameters of any such gates or measurements be efficiently computable.
Appendix B Counting complexity upper bounds on quantum simulation
In order to consider how we may obtain containments for quantum computing using counting complexity, we give an outline of the known techniques for relating quantum computation to counting complexity, and the (mild) technical constraints on coefficients of gates and of ZX-diagrams which this involves.
We are frequently interested in unitary circuits whose gates have coefficients which are irrational. However, in practise, the (finite) gate-sets of most interest involve only algebraic coefficients: that is to say, complex numbers (e.g., and for integers ) which satisfy , for some polynomial with integer coefficients. As such coefficients are dense in the complex numbers, and in particular are also dense in the subset of the complex numbers which have unit modulus, coefficients of this sort are appropriate to (approximately) represent gates which we may normally think of as being drawn from continuous, single-parameter families of gates such as and . This motivates a restriction to gates, whose coefficients are represented by algebraic numbers.
We refine this constraint as follows. By virtue of a circuit having only finitely many gates , the coefficients of the gates can in principle be drawn from a common algebraic number field , where each is a root of some (irreducible) polynomial as above and where . (For a finite gate-set, will in fact be a constant independent of .) We adopt the requirement on the representation of a circuit, that the coefficients for its gates be explicitly represented in a form
for some constant and for some choice of integer coefficients , where for each . (Following Ref. , for a finite gate-set, this does not limit the computational power of unitary circuits either for exact or for bounded-error quantum computation.) A product of such coefficients, may be represented in a similar form, but with a leading factor of rather than ; sums of such products may be represented in the same way by collecting terms together. For two numbers represented in this form, we may put them into normal form by comparing each of the terms (for some fixed sequence of powers ), and testing equality of each integer coefficient. The significance of this, is that a circuit with gates, where the individual gates satisfy such conditions, represent unitary transformations whose coefficients take this form. This provides us with a way in which the coefficients of operators given as unitary circuits, may be represented in such a way that we can efficiently perform equality comparisons in principle;333It is in principle possible to extend this representation in some ways, to allow equality comparisons between coefficients which are not algebraic; but this is not practically important to us. the question is then how we bound the complexity of doing so.
Using the techniques of Ref. , we may represent the coefficients of a unitary operator indirectly, using the number of accepting paths of nondeterministic Turing machines with various strings written on the tape to represent the integers of an algebraic number as above.444To be more precise: we may represent such an integer as a difference , where each is itself the number of accepting branches on the nondeterministic Turing machine, with slightly different contents of its tape. Then, with access to a #P oracle, a deterministic Turing machine would be able to evaluate any one coefficient . Furthermore: the techniques of Ref.  are not specialised in any particular way to unitary matrices, or indeed to square matrices, and can be applied to a matrix of any shape (or indeed, any tensor network) with algebraic coefficients. In particular, we may use these techniques to similarly represent the coefficients of linear operators which are represented by ZX-diagrams — assuming again that the coefficients arising from each generator is algebraic. The coefficients of the operators described in Eq. (2) are either , , or of the form or for various phase angles and integers . For these to all be algebraic, it suffices that the phase angles of the ZX-diagrams are rational multiples of (though other values of would also satisfy this constraint).555Technically, for any rational multiple described in the diagram, we also require that a prime factorisation of is provided. (This is an implicit requirement for the representation described above of elements of a number field .) For the purposes of practical numerical computation, this can be fulfilled by taking for a sufficiently large value of . Alternatively, if one were to use such a representation within a model of computation with access to a #P oracle, one might simply factorise by making use of the #P oracle to facilitate a binary search for factors of . We may also consider the coefficients which arise from multiplying the matrix represented by a ZX-diagram, by the matrix represented by a unitary circuit; this requires only that we represent the coefficients of each in a consistent way in terms of a common algebraic number field . From representations of the gates and of the coefficients of the ZX-generators, this would not be difficult to compute.
The above suffices to describe, in outline, how we may describe the coefficients of a linear operator — described by a unitary circuit, a ZX-diagram, or compositions of these representations — by counting the number of accepting branches of non-deterministic Turing machines. In particular, for any one coefficient , a deterministic Turing machine with a #P oracle can evaluate any particular integer . If the degree666A number field such as we have considered, can be interpreted as a vector space over the rational numbers , with a ‘basis’ described by the monomials for various integers . The degree is then the dimension of as a vector space over , and may be computed as the product of the degrees of the irreducible polynomials . of the field extension is ‘small’ (i.e., a constant, or more generally bounded by a polynomial in the size of the description of as a composition of simpler operators), we may simply query each such integer to obtain complete information of a single coefficient of . (If the degree is not ‘small’ in this sense, one might consider subtler strategies to obtain information about them; absence any particular promises or structure, complete information about the matrix coefficients would likely be inaccessible in polynomial time, even with recourse to a #P oracle.)