The Measurement Calculus
Abstract
Measurementbased quantum computation has emerged from the physics community as a new approach to quantum computation where the notion of measurement is the main driving force of computation. This is in contrast with the more traditional circuit model which is based on unitary operations. Among measurementbased quantum computation methods, the recently introduced oneway quantum computer [RB01] stands out as fundamental.
We develop a rigorous mathematical model underlying the oneway quantum computer and present a concrete syntax and operational semantics for programs, which we call patterns, and an algebra of these patterns derived from a denotational semantics. More importantly, we present a calculus for reasoning locally and compositionally about these patterns. We present a rewrite theory and prove a general standardization theorem which allows all patterns to be put in a semantically equivalent standard form. Standardization has farreaching consequences: a new physical architecture based on performing all the entanglement in the beginning, parallelization by exposing the dependency structure of measurements and expressiveness theorems.
Furthermore we formalize several other measurementbased models e.g. Teleportation, Phase and Pauli models and present compositional embeddings of them into and from the oneway model. This allows us to transfer all the theory we develop for the oneway model to these models. This shows that the framework we have developed has a general impact on measurementbased computation and is not just particular to the oneway quantum computer.
1 Introduction
The emergence of quantum computation has changed our perspective on many fundamental aspects of computing: the nature of information and how it flows, new algorithmic design strategies and complexity classes and the very structure of computational models [NC00]. New challenges have been raised in the physical implementation of quantum computers. This paper is a contribution to a nascent discipline: quantum programming languages.
This is more than a search for convenient notation, it is an investigation into the structure, scope and limits of quantum computation. The main issues are questions about how quantum processes are defined, how quantum algorithms compose, how quantum resources are used and how classical and quantum information interact.
Quantum computation emerged in the early 1980s with Feynman’s observations about the difficulty of simulating quantum systems on a classical computer. This hinted at the possibility of turning around the issue and exploiting the power of quantum systems to perform computational tasks more efficiently than was classically possible. In the mid 1980s Deutsch [Deutsch87] and later Deutsch and Jozsa [DJ92] showed how to use superposition – the ability to produce linear combinations of quantum states – to obtain computational speedup. This led to interest in algorithm design and the complexity aspects of quantum computation by computer scientists. The most dramatic results were Shor’s celebrated polytime factorization algorithm [Shor94] and Grover’s sublinear search algorithm [Grover98a]. Remarkably one of the problematic aspects of quantum theory, the presence of nonlocal correlation – an example of which is called “entanglement” – turned out to be crucial for these algorithmic developments.
If efficient factorization is indeed possible in practice, then much of cryptography becomes insecure as it is based on the difficulty of factorization. However, entanglement makes it possible to design unconditionally secure key distribution [BB84, Ekert91]. Furthermore, entanglement led to the remarkable – but simple – protocol for transferring quantum states using only classical communication [teleport93]; this is the famous socalled “teleportation” protocol. There continues to be tremendous activity in quantum cryptography, algorithmic design, complexity and information theory. Parallel to all this work there has been intense interest from the physics community to explore possible implementations, see, for example, [NC00] for a textbook account of some of these ideas.
On the other hand, only recently has there been significant interest in quantum programming languages; i.e. the development of formal syntax and semantics and the use of standard machinery for reasoning about quantum information processing. The first quantum programming languages were variations on imperative probabilistic languages and emphasized logic and program development based on weakest preconditions [Sanders00, Omer01]. The first definitive treatment of a quantum programming language was the flowchart language of Selinger [Selinger04]. It was based on combining classical control, as traditionally seen in flowcharts, with quantum data. It also gave a denotational semantics based on completely positive linear maps. The notion of quantum weakest preconditions was developed in [DP04]. Later people proposed languages based on quantum control [AG05]. The search for a sensible notion of highertype computation [SV05, vanTonder04] continues, but is problematic [selinger04b].
A related recent development is the work of Abramsky and Coecke [AbrCoe04, Coe04] where they develop a categorical axiomatization of quantum mechanics. This can be used to verify the correctness of quantum communication protocols. It is very interesting from a foundational point of view and allows one to explore exactly what mathematical ingredients are required to carry out certain quantum protocols. This has also led to work on a categorical quantum logic [AD04].
The study of quantum communication protocols has led to formalizations based on process algebras [GR04, JL04] and to proposals to use model checking for verifying quantum protocols. A survey and a complete list of references on this subject up to 2005 is available [Gay05].
These ideas have proven to be of great utility in the world of classical computation. The use of logics, type systems, operational semantics, denotational semantics and semanticbased inference mechanisms have led to notable advances such as: the use of model checking for verification, reasoning compositionally about security protocols, refinementbased programming methodology and flow analysis.
The present paper applies this paradigm to a very recent development: measurementbased quantum computation. None of the cited research on quantum programming languages is aimed at measurementbased computation. On the other hand, the work in the physics literature does not clearly separate the conceptual layers of the subject from implementation issues. A formal treatment is necessary to analyze the foundations of measurementbased computation.
So far the main framework to explore quantum computation has been the circuit model [Deutsch89], based on unitary evolution. This is very useful for algorithmic development and complexity analysis [BV97]. There are other models such as quantum Turing machines [Deutsch85] and quantum cellular automata [Watrous95, vanDam96, DS96, SW04]. Although they are all proved to be equivalent from the point of view of expressive power, there is no agreement on what is the canonical model for exposing the key aspects of quantum computation.
Recently physicists have introduced novel ideas based on the use of measurement and entanglement to perform computation [Gott99, RB01, mqqcs, Nielsen03]. This is very different from the circuit model where measurement is done only at the end to extract classical output. In measurementbased computation the main operation to manipulate information and control computation is measurement. This is surprising because measurement creates indeterminacy, yet it is used to express deterministic computation defined by a unitary evolution.
The idea of computing based on measurements emerged from the teleportation protocol [teleport93]. The goal of this protocol is for an agent to transmit an unknown qubit to a remote agent without actually sending the qubit. This protocol works by having the two parties share a maximally entangled state called a Bell pair. The parties perform local operations – measurements and unitaries – and communicate only classical bits. Remarkably, from this classical information the second party can reconstruct the unknown quantum state. In fact one can actually use this to compute via teleportation by choosing an appropriate measurement [Gott99]. This is the key idea of measurementbased computation.
It turns out that the above method of computing is actually universal. This was first shown by Gottesman and Chuang [Gott99] who used twoqubit measurements and given Bell pairs. Later Nielsen [Nielsen03] showed that one could do this with only 4qubit measurements with no prior Bell pairs, however this works only probabilistically. Leung [L03] improved this to two qubits, but her method also works only probabilistically. Later Perdrix and Jorrand [Perdrix04, PJ04] gave the minimal set measurements to perform universal quantum computing – but still in the probabilistic setting – and introduced the statetransfer and measurementbased quantum Turing machine. Finally the oneway computer was invented by Raussendorf and Briegel [RB01, RB02] which used only singlequbit measurements with a particular multiparty entangled state, the cluster state.
More precisely, a computation consists of a phase in which a collection of qubits are set up in a standard entangled state. Then measurements are applied to individual qubits and the outcomes of the measurements may be used to determine further measurements. Finally – again depending on measurement outcomes – local unitary operators, called corrections, are applied to some qubits; this allows the elimination of the indeterminacy introduced by measurements. The phrase “oneway” is used to emphasize that the computation is driven by irreversible measurements.
There are at least two reasons to take measurementbased models seriously: one conceptual and one pragmatic. The main pragmatic reason is that the oneway model is believed by physicists to lend itself to easier implementations [Nielsen04, CMJ04, BR04, TPKV04, TPKV05, nature05, KPA05, BES05, CCWD05, BBFM05]. Physicists have investigated various properties of the cluster state and have accrued evidence that the physical implementation is scalable and robust against decoherence [Schl03, graphstates, DAB03, VDD04b, VDD04, MP04, GHW05, HDB05, DHN06]. Conceptually the measurementbased model highlights the role of entanglement and separates the quantum and classical aspects of computation; thus it clarifies, in particular, the interplay between classical control and the quantum evolution process.
Our approach to understanding the structural features of measurementbased computation is to develop a formal calculus. One can think of this as an “assembly language” for measurementbased computation. Ours is the first programming framework specifically based on the oneway model. We first develop a notation for such classically correlated sequences of entanglements, measurements, and local corrections. Computations are organized in patterns^{1}^{1}1We use the word “pattern” rather than “program”, because this corresponds to the commonly used terminology in the physics literature., and we give a careful treatment of the composition and tensor product (parallel composition) of patterns. We show next that such pattern combinations reflect the corresponding combinations of unitary operators. An easy proof of universality follows.
So far, this is primarily a clarification of what was already known from the series of papers introducing and investigating the properties of the oneway model [RB01, RB02, mqqcs]. However, we work here with an extended notion of pattern, where inputs and outputs may overlap in any way one wants them to, and this results in more efficient – in the sense of using fewer qubits – implementations of unitaries. Specifically, our universal set consists of patterns using only 2 qubits. From it we obtain a 3 qubit realization of the R_{z} rotations and a 14 qubit realization for the controlledU family: a significant reduction over the hitherto known implementations.
The main point of this paper is to introduce a calculus of local equations over patterns that exploits some special algebraic properties of the entanglement, measurement and correction operators. More precisely, we use the fact that that 1qubit XY measurements are closed under conjugation by Pauli operators and the entanglement command belongs to the normalizer of the Pauli group; these terms are explained in the appendix. We show that this calculus is sound in that it preserves the interpretation of patterns. Most importantly, we derive from it a simple algorithm by which any general pattern can be put into a standard form where entanglement is done first, then measurements, then corrections. We call this standardization.
The consequences of the existence of such a procedure are farreaching. Since entangling comes first, one can prepare the entire entangled state needed during the computation right at the start: one never has to do “on the fly” entanglements. Furthermore, the rewriting of a pattern to standard form reveals parallelism in the pattern computation. In a general pattern, one is forced to compute sequentially and to strictly obey the command sequence, whereas, after standardization, the dependency structure is relaxed, resulting in lower computational depth complexity. Last, the existence of a standard form for any pattern also has interesting corollaries beyond implementation and complexity matters, as it follows from it that patterns using no dependencies, or using only the restricted class of Pauli measurements, can only realize a unitary belonging to the Clifford group, and hence can be efficiently simulated by a classical computer [Gottesman97].
As we have noted before, there are other methods for measurementbased quantum computing: the teleportation technique based on twoqubit measurements and the statetransfer approach based on single qubit measurements and incomplete twoqubit measurements. We will analyze the teleportation model and its relation to the oneway model. We will show how our calculus can be smoothly extended to cover this case as well as new models that we introduce in this paper. We get several benefits from our treatment. We get a workable syntax for handling the dependencies of operators on previous measurement outcomes just by mimicking the one obtained in the oneway model. This has never been done before for the teleportation model. Furthermore, we can use this embedding to obtain a standardization procedure for the models. Finally these extended calculi can be compositionally embedded back in the original oneway model. This clarifies the relation between different measurementbased models and shows that the oneway model of Raussendorf and Briegel is the canonical one.
This paper develops the oneway model ab initio but certain concepts that the reader may be unfamiliar with: qubits, unitaries, measurements, Pauli operators and the Clifford group are in an appendix. These are also readily accessible through the very thorough book of Nielsen and Chuang [NC00].
In the next section we define the basic model, followed by its operational and denotational semantics, for completeness a simple proof of universality is given in section LABEL:s:univ, this has appeared earlier in the physics literature [generator04], in section LABEL:scal we develop the rewrite theory and prove the fundamental standardization theorem. In section LABEL:s:examples we develop several examples that illustrate the use of our calculus in designing efficient patterns. In section LABEL:s:expr we prove some theorems about the expressive power of the calculus in the absence of adaptive measurements. In section LABEL:s:other we discuss other measurementbased models and their compositional embedding to and from the oneway model. In section LABEL:s:conc we discuss further directions and some more related work. In the appendix we review basic notions of quantum mechanics and quantum computation.
2 Measurement Patterns
We first develop a notation for 1qubit measurement based computations. The basic commands one can use in a pattern are:

1qubit auxiliary preparation N_{i}

2qubit entanglement operators E_{ij}

1qubit measurements {M}_{i}^{\alpha}

and 1qubit Pauli operators corrections X_{i} and Z_{i}
The indices i, j represent the qubits on which each of these operations apply, and \alpha is a parameter in [0,2\pi]. Expressions involving angles are always evaluated modulo 2\pi. These types of command will be referred to as N, E, M and C. Sequences of such commands, together with two distinguished – possibly overlapping – sets of qubits corresponding to inputs and outputs, will be called measurement patterns, or simply patterns. These patterns can be combined by composition and tensor product.
Importantly, corrections and measurements are allowed to depend on previous measurement outcomes. We shall prove later that patterns without these classical dependencies can only realize unitaries that are in the Clifford group. Thus, dependencies are crucial if one wants to define a universal computing model; that is to say, a model where all unitaries over \otimes^{n}{\mathbb{C}}^{2} can be realized. It is also crucial to develop a notation that will handle these dependencies. This is what we do now.
2.1 Commands
Preparation N_{i} prepares qubit i in state {}+\rangle_{i}. The entanglement commands are defined as E_{ij}:=\mathop{\wedge}\hskip1.72ptZ_{ij} (controlledZ), while the correction commands are the Pauli operators X_{i} and Z_{i}.
Measurement {M}_{i}^{\alpha} is defined by orthogonal projections on
\begin{array}[c]{lllllllllllllll}{}\hskip0.43pt+_{\alpha}\rangle&:=&\frac{1}% {\sqrt{2}}({}0\rangle+e^{i\alpha}{}1\rangle)\\ {}\hskip0.43pt_{\alpha}\rangle&:=&\frac{1}{\sqrt{2}}({}0\ranglee^{i\alpha% }{}1\rangle)\end{array} 
followed by a traceout operator. The parameter \alpha\in[0,2\pi] is called the angle of the measurement. For \alpha=0, \alpha=\frac{\pi}{2}, one obtains the X and Y Pauli measurements. Operationally, measurements will be understood as destructive measurements, consuming their qubit. The outcome of a measurement done at qubit i will be denoted by s_{i}\in{\mathbb{Z}}_{2}. Since one only deals here with patterns where qubits are measured at most once (see condition (D1) below), this is unambiguous. We take the specific convention that s_{i}=0 if under the corresponding measurement the state collapses to {}\hskip0.43pt+_{\alpha}\rangle, and s_{i}=1 if to {}\hskip0.43pt_{\alpha}\rangle.
Outcomes can be summed together resulting in expressions of the form s=\sum_{i\in I}s_{i} which we call signals, and where the summation is understood as being done in {\mathbb{Z}}_{2}. We define the domain of a signal as the set of qubits on which it depends.
As we have said before, both corrections and measurements may depend on signals. Dependent corrections will be written X_{i}^{s} and Z_{i}^{s} and dependent measurements will be written {}^{t}[{M}_{i}^{\alpha}]^{s}, where s,t\in{\mathbb{Z}}_{2} and \alpha\in[0,2\pi]. The meaning of dependencies for corrections is straightforward: X_{i}^{0}=Z_{i}^{0}=I, no correction is applied, while X_{i}^{1}=X_{i} and Z_{i}^{1}=Z_{i}. In the case of dependent measurements, the measurement angle will depend on s, t and \alpha as follows:
\displaystyle{}^{t}[{M}_{i}^{\alpha}]^{s}  \displaystyle:=  \displaystyle{M}_{i}^{(1)^{s}\alpha+t\pi}  (1) 
so that, depending on the parities of s and t, one may have to modify the \alpha to one of \alpha, \alpha+\pi and \alpha+\pi. These modifications correspond to conjugations of measurements under X and Z:
\displaystyle X_{i}{M}_{i}^{{\alpha}}X_{i}  \displaystyle=  \displaystyle{M}_{i}^{{\alpha}}  (2)  
\displaystyle Z_{i}{M}_{i}^{{\alpha}}Z_{i}  \displaystyle=  \displaystyle{M}_{i}^{{\alpha+\pi}}  (3) 
accordingly, we will refer to them as the X and Zactions. Note that these two actions commute, since \alpha+\pi=\alpha\pi up to 2\pi, and hence the order in which one applies them does not matter.
As we will see later, relations (2) and (3) are key to the propagation of dependent corrections, and to obtaining patterns in the standard entanglement, measurement and correction form. Since the measurements considered here are destructive, the above equations actually simplify to
\displaystyle{M}_{i}^{{\alpha}}X_{i}  \displaystyle=  \displaystyle{M}_{i}^{{\alpha}}  (4)  
\displaystyle{M}_{i}^{{\alpha}}Z_{i}  \displaystyle=  \displaystyle{M}_{i}^{{\alpha\pi}}  (5) 
Another point worth noticing is that the domain of the signals of a dependent command, be it a measurement or a correction, represents the set of measurements which one has to do before one can determine the actual value of the command.
We have completed our catalog of basic commands, including dependent ones, and we turn now to the definition of measurement patterns. For convenient reference, the language syntax is summarized in Figure 1.
\begin{array}[]{lllr}S&:=&0,\,1,\,s_{i},\,S+S&\quad\hbox{Signals}\\ A&:=&N_{i}&\quad\hbox{Preparations}\\ &&E_{ij}&\quad\hbox{Entanglements}\\ &&{}^{t}[{M}_{i}^{\alpha}]^{s}&\quad\hbox{Measurements}\\ &&X_{i}^{s},\,Z_{i}^{s}&\quad\hbox{Corrections}\end{array} 
2.2 Patterns
Definition 1
Patterns consists of three finite sets V, I, O, together with two injective maps \iota:I\rightarrow V and o:O\rightarrow V and a finite sequence of commands A_{n}\ldots A_{1}, read from right to left, applying to qubits in V in that order, i.e. A_{1} first and A_{n} last, such that:
 (D0)

no command depends on an outcome not yet measured;
 (D1)

no command acts on a qubit already measured;
 (D2)

no command acts on a qubit not yet prepared, unless it is an input qubit;
 (D3)

a qubit i is measured if and only if i is not an output.
The set V is called the pattern computation space, and we write \mathfrak{H}_{V} for the associated quantum state space \otimes_{i\in V}{\mathbb{C}}^{2}. To ease notation, we will omit the maps \iota and o, and write simply I, O instead of \iota(I) and o(O). Note, however, that these maps are useful to define classical manipulations of the quantum states, such as permutations of the qubits. The sets I, O are called respectively the pattern inputs and outputs, and we write \mathfrak{H}_{I}, and \mathfrak{H}_{O} for the associated quantum state spaces. The sequence A_{n}\ldots A_{1} is called the pattern command sequence, while the triple (V,I,O) is called the pattern type.
To run a pattern, one prepares the input qubits in some input state \psi\in\mathfrak{H}_{I}, while the noninput qubits are all set to the {}+\rangle state, then the commands are executed in sequence, and finally the result of the pattern computation is read back from outputs as some \phi\in\mathfrak{H}_{O}. Clearly, for this procedure to succeed, we had to impose the (D0), (D1), (D2) and (D3) conditions. Indeed if (D0) fails, then at some point of the computation, one will want to execute a command which depends on outcomes that are not known yet. Likewise, if (D1) fails, one will try to apply a command on a qubit that has been consumed by a measurement (recall that we use destructive measurements). Similarly, if (D2) fails, one will try to apply a command on a nonexistent qubit. Condition (D3) is there to make sure that the final state belongs to the output space \mathfrak{H}_{O}, i.e., that all nonoutput qubits, and only nonoutput qubits, will have been consumed by a measurement when the computation ends.
We write (D) for the conjunction of our definiteness conditions (D0), (D1), (D2) and (D3). Whether a given pattern satisfies (D) or not is statically verifiable on the pattern command sequence. We could have imposed a simple type system to enforce these constraints but, in the interests of notational simplicity, we chose not to do so.
Here is a concrete example:
\begin{array}[c]{lllllllllllllll}\mathcal{H}&:=&(\{1,2\},\{1\},\{2\},X_{2}^{s_% {1}}{M}_{1}^{0}E_{12}N_{2})\end{array} 
with computation space \{1,2\}, inputs \{1\}, and outputs \{2\}. To run \mathcal{H}, one first prepares the first qubit in some input state \psi, and the second qubit in state {}+\rangle, then these are entangled to obtain \mathop{\wedge}\hskip1.72ptZ_{12}(\psi_{1}\otimes{}+\rangle_{2}). Once this is done, the first qubit is measured in the {}+\rangle, {}\rangle basis. Finally an X correction is applied on the output qubit, if the measurement outcome was s_{1}=1. We will do this calculation in detail later, and prove that this pattern implements the Hadamard operator H.
In general, a given pattern may use auxiliary qubits that are neither input nor output qubits. Usually one tries to use as few such qubits as possible, since these contribute to the space complexity of the computation.
A last thing to note is that one does not require inputs and outputs to be disjoint subsets of V. This, seemingly innocuous, additional flexibility is actually quite useful to give parsimonious implementations of unitaries [generator04]. While the restriction to disjoint inputs and outputs is unnecessary, it has been discussed whether imposing it results in patterns that are easier to realize physically. Recent work [graphstates, BR04, CMJ04] however, seems to indicate it is not the case.
2.3 Pattern combination
We are interested in how one can combine patterns in order to obtain bigger ones.
The first way to combine patterns is by composing them. Two patterns \mathcal{P}_{1} and \mathcal{P}_{2} may be composed if V_{1}\cap V_{2}=O_{1}=I_{2}. Provided that \mathcal{P}_{1} has as many outputs as \mathcal{P}_{2} has inputs, by renaming the pattern qubits, one can always make them composable.
Definition 2
The composite pattern \mathcal{P}_{2}\mathcal{P}_{1} is defined as:
— V:=V_{1}\cup V_{2}, I=I_{1}, O=O_{2},
— commands are concatenated.
The other way of combining patterns is to tensor them. Two patterns \mathcal{P}_{1} and \mathcal{P}_{2} may be tensored if V_{1}\cap V_{2}=\varnothing. Again one can always meet this condition by renaming qubits in a way that these sets are made disjoint.
Definition 3
The tensor pattern \mathcal{P}_{1}\otimes\mathcal{P}_{2} is defined as:
— V=V_{1}\cup V_{2}, I=I_{1}\cup I_{2}, and O=O_{1}\cup O_{2},
— commands are concatenated.
In contrast to the composition case, all the unions involved here are disjoint. Therefore commands from distinct patterns freely commute, since they apply to disjoint qubits, and when we say that commands have to be concatenated, this is only for definiteness. It is routine to verify that the definiteness conditions (D) are preserved under composition and tensor product.
Before turning to this matter, we need a clean definition of what it means for a pattern to implement or to realize a unitary operator, together with a proof that the way one can combine patterns is reflected in their interpretations. This is key to our proof of universality.
3 The semantics of patterns
In this section we give a formal operational semantics for the pattern language as a probabilistic labeled transition system. We define deterministic patterns and thereafter concentrate on them. We show that deterministic patterns compose. We give a denotational semantics of deterministic patterns; from the construction it will be clear that these two semantics are equivalent.
Besides quantum states, which are nonzero vectors in some Hilbert space \mathfrak{H}_{V}, one needs a classical state recording the outcomes of the successive measurements one does in a pattern. If we let V stand for the finite set of qubits that are still active (i.e. not yet measured) and W stands for the set of qubits that have been measured (i.e. they are now just classical bits recording the measurement outcomes), it is natural to define the computation state space as:
\begin{array}[c]{lllllllllllllll}\mathcal{S}&:=&\Sigma_{V,W}\mathfrak{H}_{V}% \times{\mathbb{Z}}_{2}^{W}.\end{array} 
In other words the computation states form a V,Windexed family of pairs^{2}^{2}2These are actually quadruples of the form (V,W,q,\Gamma), unless necessary we will suppress the V and the W. q, \Gamma, where q is a quantum state from \mathfrak{H}_{V} and \Gamma is a map from some W to the outcome space {\mathbb{Z}}_{2}. We call this classical component \Gamma an outcome map, and denote by \varnothing the empty outcome map in {\mathbb{Z}}_{2}^{\varnothing}. We will treat these states as pairs unless it becomes important to show how V and W are altered during a computation, as happens during a measurement.
3.1 Operational semantics
We need some preliminary notation. For any signal s and classical state \Gamma\in{\mathbb{Z}}_{2}^{W}, such that the domain of s is included in W, we take s_{\Gamma} to be the value of s given by the outcome map \Gamma. That is to say, if s=\sum_{I}s_{i}, then s_{\Gamma}:=\sum_{I}\Gamma(i) where the sum is taken in {\mathbb{Z}}_{2}. Also if \Gamma\in{\mathbb{Z}}_{2}^{W}, and x\in{\mathbb{Z}}_{2}, we define:
\begin{array}[c]{lllllllllllllll}\Gamma[x/i](i)=x,\,\Gamma[x/i](j)=\Gamma(j)% \hbox{ for }j\neq i\end{array} 
which is a map in {\mathbb{Z}}_{2}^{W\cup\{i\}}.
We may now view each of our commands as acting on the state space \mathcal{S}, we have suppressed V and W in the first 4 commands:
\begin{array}[c]{lllllllllllllll}q,\Gamma&\lx@stackrel{{\scriptstyle N_{i}}}{{% \longrightarrow}}&q\otimes{}+\rangle_{i},\Gamma\\ q,\Gamma&\lx@stackrel{{\scriptstyle E_{ij}}}{{\longrightarrow}}&\mathop{\wedge% }\hskip1.72ptZ_{ij}q,\Gamma\\ q,\Gamma&\lx@stackrel{{\scriptstyle X_{i}^{s}}}{{\longrightarrow}}&X_{i}^{s_{% \Gamma}}q,\Gamma\\ q,\Gamma&\lx@stackrel{{\scriptstyle Z_{i}^{s}}}{{\longrightarrow}}&Z_{i}^{s_{% \Gamma}}q,\Gamma\\ V\cup\{i\},W,q,\Gamma&\lx@stackrel{{\scriptstyle{}^{t}[{M}_{i}^{\alpha}]^{s}}}% {{\longrightarrow}}&V,W\cup\{i\},{\langle\hskip0.43pt+_{\alpha_{\Gamma}}{}}_% {i}q,\Gamma[0/i]\\ V\cup\{i\},W,q,\Gamma&\lx@stackrel{{\scriptstyle{}^{t}[{M}_{i}^{\alpha}]^{s}}}% {{\longrightarrow}}&V,W\cup\{i\},{\langle\hskip0.43pt_{\alpha_{\Gamma}}{}}_% {i}q,\Gamma[1/i]\end{array} 
where \alpha_{\Gamma}=(1)^{s_{\Gamma}}\alpha+t_{\Gamma}\pi following equation (1). Note how the measurement moves an index from V to W; a qubit once measured cannot be neasured again. Suppose q\in\mathfrak{H}_{V}, for the above relations to be defined, one needs the indices i, j on which the various command apply to be in V. One also needs \Gamma to contain the domains of s and t, so that s_{\Gamma} and t_{\Gamma} are welldefined. This will always be the case during the run of a pattern because of condition (D).
All commands except measurements are deterministic and only modify the quantum part of the state. The measurement actions on \mathcal{S} are not deterministic, so that these are actually binary relations on \mathcal{S}, and modify both the quantum and classical parts of the state. The usual convention has it that when one does a measurement the resulting state is renormalized and the probabilities are associated with the transition. We do not adhere to this convention here, instead we leave the states unnormalized. The reason for this choice of convention is that this way, the probability of reaching a given state can be read off its norm, and the overall treatment is simpler. As we will show later, all the patterns implementing unitary operators will have the same probability for all the branches and hence we will not need to carry these probabilities explicitly.
We introduce an additional command called signal shifting:
\begin{array}[c]{lllllllllllllll}q,\Gamma&\lx@stackrel{{\scriptstyle S_{i}^{s}% }}{{\longrightarrow}}&q,\Gamma[\Gamma(i)+s_{\Gamma}/i]\end{array} 
It consists in shifting the measurement outcome at i by the amount s_{\Gamma}. Note that the Zaction leaves measurements globally invariant, in the sense that {}\hskip0.43pt+_{\alpha+\pi}\rangle,{}\hskip0.43pt_{\alpha+\pi}\rangle={% }\hskip0.43pt_{\alpha}\rangle,{}\hskip0.43pt+_{\alpha}\rangle. Thus changing \alpha to \alpha+\pi amounts to swapping the outcomes of the measurements, and one has:
\displaystyle{}^{t}[{M}_{i}^{\alpha}]^{s}  \displaystyle=  \displaystyle S_{i}^{t}\,{}^{0}[{M}_{i}^{\alpha}]^{s}  (6) 
and signal shifting allows to dispose of the Z action of a measurement, resulting sometimes in convenient optimizations of standard forms.
3.2 Denotational semantics
Let \mathcal{P} be a pattern with computation space V, inputs I, outputs O and command sequence A_{n}\ldots A_{1}. To execute a pattern, one starts with some input state q in \mathfrak{H}_{I}, together with the empty outcome map \varnothing. The input state q is then tensored with as many {}+\rangles as there are noninputs in V (the N commands), so as to obtain a state in the full space \mathfrak{H}_{V}. Then E, M and C commands in \mathcal{P} are applied in sequence from right to left. We can summarize the situation as follows:
\begin{array}[c]{lllllllllllllll}\xymatrix@=10pt@M=5pt@R=20pt@C=40pt{{}% \mathfrak{H}_{I}{}{}{}{}{}{}{}{}{}{}\xy@@ix@{{\hbox{}\end{array}}}} 