The XP Stabiliser Formalism: a Generalisation of the Pauli Stabiliser Formalism with Arbitrary Phases

We propose an extension to the Pauli stabiliser formalism that includes fractional $2\pi/N$ rotations around the $Z$ axis for some integer $N$. The resulting generalised stabiliser formalism - denoted the XP stabiliser formalism - allows for a wider range of states and codespaces to be represented. We describe the states which arise in the formalism, and demonstrate an equivalence between XP stabiliser states and 'weighted hypergraph states' - a generalisation of both hypergraph and weighted graph states. Given an arbitrary set of XP operators, we present algorithms for determining the codespace and logical operators for an XP code. Finally, we consider whether measurements of XP operators on XP codes can be classically simulated.


Introduction
Representing general quantum states of n qubits requires an amount of information that is exponential in n. For tractable theoretical study of quantum systems, we require more compact representations of quantum states of interest. Some examples of such representations include tensor network states e.g. Matrix Product States and Projected Entangled Pair States [20] and states created by low-depth quantum circuits [9].
The Pauli stabiliser formalism allows for the efficient description and manipulation of an important subset of quantum states, known as Pauli stabiliser states [12]. Pauli stabiliser states and codes can be efficiently described using a set of stabiliser generators, which are elements of the Pauli group iI, X, Z ⊗n , with only n such generators needed to describe a Pauli stabiliser state. Many key quantum features such as entanglement and superposition can be captured using stabiliser states. Given the stabiliser generators, efficient algorithms exist for determining the codespace, logical operators and simulating measurements of Pauli operators. On the other hand, the states which can be represented within the Pauli stabiliser formalism are quite limited. The fact that we can simulate the behaviour of Pauli stabiliser states suggests that we are missing some important aspects of quantum advantage.
Given the ubiquity and the utility of the Pauli stabiliser formalism in quantum information theory, it is no surprise that there have been several studies into generalising this formalism in order to broaden the classes of stabiliser states. One such approach is the qudit stabiliser formalism, where we fix a dimension D and stabiliser generators are from the generalised Pauli group on D-level systems. The algorithms from the Pauli stabiliser formalism can be extended to qudit codes [11], and measurement of any generalised Pauli group operator is known to be classically simulable [2].
Another generalisation is the XS stabiliser formalism [18], wherein stabiliser codes are defined using elements of αI, X, S ⊗n which act on qubits and where α := e iπ/4 and S := diag(1, i) is the phase gate. In Ref. [18], the authors demonstrate that states outside the Pauli stabiliser formalism can be represented as XS stabiliser states. In particular, they demonstrate that Quantum Twisted Mark A. Webster: mark.webster@sydney.edu.au Double models which harbour non-Abelian anyons can be represented in the XS formalism. The authors present algorithms for determining the codespace, expectation values and logical operators for such codes, but these are limited to certain 'regular' codes.
In this paper, we introduce the XP stabiliser formalism which generalises the concept of the XS formalism. In the XP formalism, we fix an integer N and define XP codes using elements of ωI, X, P ⊗n where ω := e iπ/N , P := diag(1, ω 2 ). We prove that hypergraph and weighted graph states can be represented as XP stabiliser states. These are useful classes of states which cannot be represented as Pauli stabiliser states. We present XP versions of many of the algorithms available in the Pauli stabiliser formalism, which apply to any XP code. This includes algorithms to determine the codespace, logical operators and simulate the measurement of diagonal Pauli operators on an XP codespace. Computational complexity of these tasks increases with the precision N of the code. We demonstrate that measurement of XP operators on a codespace is not always efficiently simulable. Hence, the XP formalism lies on the boundary between what is classically simulable and what is not, suggesting that we may be able to capture some aspects of quantum advantage.
The XP stabiliser formalism has a number of potential applications. For instance, the logical operator structure of XP codes is much richer than is the case for Pauli stabiliser codes. We could potentially use the XP formalism to describe codes with transversal logical non-Clifford operations (for instance T or CCZ gates) that could be used for fault-tolerant preparation of magic states. As the stabiliser generators of XP codes do not commute, certain no-go theorems may not apply, for instance, in the area of quantum memories [4]. Compared to the Pauli stabiliser formalism, a wider range of topological phases can be represented, which makes studying them more straightforward using the techniques presented in this paper.
This paper is structured to present the framework and tools necessary to start exploration of the XP formalism, with examples used throughout the paper. Where possible, examples are linked to interactive Jupyter notebooks that allow for further exploration and modification of these examples by the reader.
In Chapter 2, we review the Pauli stabiliser formalism and the XS Formalism introduced in Ref. [18]. We then introduce the XP formalism and summarise the main results of this paper. In Chapter 3, we set out definitions for XP operators and give a full description of their algebra. In Chapter 4, we show how to identify the codespace of an arbitrary set of XP operators and calculate a set of codewords which form a basis of the codespace. In Chapter 5, we classify the states which arise in the XP formalism and show that two important classes of states can be represented as XP stabiliser states: hypergraph [23] and weighted graph states [13,14].
In Chapter 6, we address the logical operator structure of XP codes. We show how to find XP operators which generate the logical operator group for a given codespace. We can allocate quantum numbers to the codewords of Chapter 4, and this leads to a classification of XP codes into XP-regular and non-XP-regular codes. We show that any XP-regular code can be mapped to a CSS code with similar logical operator structure. We show how to determine all possible logical actions which can be applied by diagonal operators and demonstrate that non-XP-regular codes give rise to logical operators with complex actions.
In Chapter 7, we look at measurements in the XP formalism. We demonstrate an efficient algorithm for simulation of measurement of diagonal Pauli operators on any XP code. Beyond this special case, XP operators cannot in general be measured within the XP formalism. Estimating measurement outcome probabilities for XP operators is in general an NP-complete problem.
We conclude in Chapter 8 with a discussion and list of outstanding questions for the XP formalism.

The XP Stabiliser Formalism
The Pauli stabiliser formalism (PSF) has been hugely valuable for describing the quantum errorcorrecting codes we need to overcome the decohering effects of the environment on quantum systems. Moreover, its structure is such that we can prove powerful results on the simulability of Clifford circuits.
Nevertheless, this formalism is limited in the types of quantum states it can describe. Extending the stabiliser formalism gives us new tools to describe more general quantum systems, and to explore their potential applications.
In this section, we first review the PSF and discuss the desirable features that we would like to carry over into an extension to the formalism. We next discuss the XS Formalism introduced in Ref. [18], which is an extension of the PSF. We then introduce our new formalism, the XP formalism, which generalises the concept of the XS Formalism. Finally, we outline the main properties of the XP formalism and summarise the results presented in this paper.

Review of the Pauli Stabiliser Formalism
Pauli stabiliser codes are amongst the most commonly studied quantum error correction codes. A stabiliser code is specified by a list of stabiliser generators. The stabiliser generators are tensor products of operators in the single-qubit Pauli group P = iI, X, Z . The stabiliser group is the group generated by the stabiliser generators. The codespace is the simultaneous +1 eigenspace of the stabiliser group. The codewords are a basis of the codespace (i.e. spanning and independent).
The power of the Pauli stabiliser formalism is that stabiliser codes can be analysed and simulated by operations on the stabiliser generators rather the codewords. In Chapter 10 of Ref. [19], efficient algorithms involving operations on the stabiliser generators are set out for the following tasks: 1. Check if a set of Pauli operators identify a non-trivial codespace: equivalent to checking whether −I is in the stabiliser group.
2. Find codewords and logical operators: represent the stabiliser generators as binary vectors which form the rows of a check matrix, then apply linear algebra techniques.
3. Simulate action of Clifford Unitary Operator U : the updated code generators are obtained by conjugating each of the generators by U . 4. Simulate measurement of Pauli Operator A: update the stabiliser generators by determining if they commute or anticommute with A.
The above properties allow us to detect and correct errors in Pauli stabiliser codes by measuring the stabiliser generators.

Extending the Pauli Stabiliser Formalism -Existing Work
The Pauli stabiliser formalism (PSF) is capable of describing only a limited subset of all possible quantum states. One way to extend the PSF is to consider qudit stabiliser codes using the Generalised Pauli Group [11], and there is a fairly substantial literature on this generalisation. Another way is to work with qubits, but to admit operators with finer rotations around the Z axis in stabiliser groups. In the XS stabiliser formalism, introduced in Ref. [18], stabiliser generators are tensor products of operators in αI, X, S where S := diag(1, i) so that S 4 = I and α := exp(iπ/4) so that α 8 = 1. The XS stabiliser formalism can describe a wider range of states compared to the PSF, meaning there are XS code states that cannot be expressed within the PSF. Examples of such XS code states are the twisted quantum double models [8].
A set of XS stabiliser generators do not need to commute to form a valid code. As a result, we cannot in general perform simultaneous measurements of the generators, as is commonly done in PSF codes for error correction. Even so, commuting parent Hamiltonians for XS codes exist, and so error correction is possible with XS codes.
In the XS stabiliser formalism, regular codes are a special case, defined as those where the diagonal generators are tensor products of −I, Z . For these regular codes, Ref. [18] presents algorithms to: calculate the codewords from a list of stabiliser generators; calculate the stabiliser generators for a given codeword; calculate logical Z and X operators for a codespace; construct a circuit to find expectation values for measurements of Pauli operators on the code.
In summary, Ref. [18] provides a useful generalisation of the PSF, as well as generalising a number of algorithms for analysing and simulating codes. One of the main limitations of the XS stabiliser formalism is that many algorithms only work for regular codes, which are a subset of possible XS codes.

The XP Stabiliser Formalism
In our work, we introduce a formalism that generalises the the XS stabiliser formalism concept, allowing us to represent an even wider set of states. We demonstrate algorithms for most of the operations we have under the PSF, with a corresponding increase in computational complexity. The algorithms work on any XP code and are not restricted to regular codes as in Ref. [18]. The XP formalism is at a similar level of generality as that presented for qudits in Ref. [11], and we prove many analogous results. The properties of XP and qudit stabiliser codes are compared in Table 1.
An XP stabiliser code is defined by fixing an integer N ≥ 2 which we refer to as the precision of the code. We then specify a set of stabiliser generators which are from ωI, X, P ⊗n where Each choice of precision N leads to a different stabiliser formalism. For example, N = 2 corresponds to the standard Pauli stabiliser formalism, with ω = i and Z 2 = I. The XS stabiliser formalism of Ref. [18] corresponds to N = 4, with ω = √ i and S 4 = I. Note that N does not need to be a power of 2 -e.g., N = 6 or N = 7 are valid choices.
Unlike the Pauli stabiliser formalism, the XPF is not closed under conjugation by Hadamard operators. In particular, if N = 2M then: One could consider expanding the formalism to allow fractional X operators of this type, but this does not lead to a finite set of operators that is closed under group operations. There are a number of open questions from Ref. [18] which we also address for both XS codes and the general XP case: • How do we find all transversal logical operators for a given code?
• Which sets of operators stabilise the same codespace?
• Can we simulate measurements efficiently?
• Which classes of states can be described within a generalisation of the stabiliser formalism?

Summary of Results
We present algorithms within the XPF for many of the operations that are possible within the Pauli stabiliser formalism (PSF). Our formalism is broader than the XS formalism and answers a number of open questions from Ref. [18]. Table 2 compares the XS stabiliser formalism with the XPF and summaries the results we demonstrate in this paper.
We start by setting out the algebra of XP operators in Chapter 3. We show how to represent XP operators as vectors of integers. By generalising the symplectic product of the PSF, we write elegant closed form expressions for the main algebraic operations on XP operators -including multiplication, inverses, powers, conjugation and commutation. We also show efficient ways to calculate the eigenvalues and the action of projectors of XP operators.
We specify XP codes by giving a list of XP operators which have a non-trivial simultaneous +1 eigenspace. In Chapter 4, we show how to identify the codespace for an arbitrary set of XP operators. In Ref. [18], a method is presented for doing this, but only for 'regular' codes where the diagonal stabiliser generators are from −I, Z ⊗n . We demonstrate an algorithm which works for any XP code, whether regular or not.
Having introduced some of the basic techniques for working with XP codes, in Chapter 5 we determine which states arise under the XP formalism. We identify the form of the phase function of XP stabiliser states and show an equivalence between 'weighted hypergraph states' and XP stabiliser states. In particular, two important classes of states -hypergraph and weighted graph states -can be represented as XP stabiliser states. We give examples which have potential uses in measurement-based quantum computation and self-correcting quantum memories.
Understanding which logical operators arise for a given XP code has important implications for which error-protected operations are possible. In Chapter 6 we show how to calculate generators for the entire group of logical operators of XP form. The algorithm works for all XP codes, and yields any non-Clifford logical operators (e.g., logical T, CCZ etc) of XP form which act on the codespace.
The stabiliser group of a codespace is not unique in the XPF, but the group of XP operators which act as logical identities on the codespace is unique. We show how to efficiently calculate generators for the logical identity group for a given XP group, resulting in a test for whether two XP groups stabilise the same codespace.
In Section 6.5 we introduce a classification of XP codes into XP-regular and non-XP-regular codes. XP-regular codes include all 'regular' codes as defined in Ref. [18], but is a broader class. We show that, as in the PSF, the codespace dimension of XP-regular codes is a power of 2. For non-XP-regular codes, the codespace dimension is arbitrary. Non-XP-regular codes are non-additive and have a structure similar to that of codeword stabilised (CWS) quantum codes [7]. Each XPregular code can be mapped to a CSS code which has a similar logical operator structure. We demonstrate that for non-XP-regular codes, more complex diagonal operators can arise compared to the PSF. A summary of the differences between XP-regular and non XP-regular codes is in Table 3.  Determining the extent to which computations on a quantum computer can be classically simulated is one of the central questions in the field of quantum information. In the Pauli stabiliser formalism, we can classically simulate the measurement of any Pauli operator on any stabiliser code. A similar result holds for the qudit stabiliser formalism for generalised Pauli group operators. Chapter 7 covers measurement in the XP formalism. Measurement of diagonal Pauli operators can be efficiently simulated on any XP code, and we present an efficient stabiliser method for calculating the outcome probabilities and updated XP code. We then consider extending the algorithm to precision 4 operators. We show that finding the outcome probabilities when measuring collections of diagonal precision 4 diagonal operators is NP-complete. We also give examples where the measurement of precision 4 operators cannot be done within the XP formalism.

Property XP-Regular
Finally in Chapter 8, we summarise what is known about the XP formalism, discuss implications, and lay out possible future research directions.

XPF Software Package
We have produced a Python software package implementing all algorithms discussed in this paper. The Github repository is made available subject to GPL licensing. Interactive Jupyter notebooks for all examples in this paper are included and can be modified to run different scenarios.

Algebra of XP Operators
In this section, we lay out fundamental results for the algebra of XP operators, including closed form expressions for algebraic operations which support efficient simulation on a classical computer. We show how to write a unique vector representation for XP operators. We generalise the symplectic product of the Pauli stabiliser formalism and show how to express algebraic operations in terms of the vector representation and the generalised symplectic product. We also introduce the concepts of the degree and fundamental phase of XP operators. These concepts allow us to determine the eigenvalues and actions of the projectors of XP operators.

Vector Representation of XP Operators
In this section, we show that there is a natural identification of XP operators on n qubits with vectors of integers. Let u = (p|x|z) ∈ Z × Z n × Z n be an integer vector of length 2n + 1. Define the XP operator of precision N corresponding to u as: where ω and P are as defined in Eqs. (1) and (2). Each component is periodic in that we can write: Accordingly, we can write a unique vector representation (p|x|z) ∈ Z 2N × Z n 2 × Z n N for each XP operator. We call p the phase component, x the X component and z the Z component.
Here we list some properties of this notation: 1. The identity XP operator is XP N (0|0|0) where 0 is the length n vector with all entries 0.
4. Diagonal operators are of form XP N (p|0|z), i.e. the X component is the zero vector.
5. If N is even, the single qubit Z operator is XP N (0|0| N 2 ). For N odd, Z operators cannot be represented as XP operators. Note that one may rescale the code to be of precision 2N by doubling the phase and Z components of stabiliser generators, in which case the rescaled code has the same codespace and accommodates Z operators. Example 3.1 (Using XP operator notation) Consider the following example of an XP operator: The precision is specified by the subscript 8, in this case N = 8. This means that ω = exp( 1 16 2πi) and In other words, this is an XT operator. Most of the examples we consider in this paper are precision N = 8 codes.
The components of A are as follows. The phase component is a value p ∈ Z 16 . In this case p = 12 means the overall phase of the operator is ω 12 = exp( 12 16 2πi) = exp( 3 4 2πi) = −i. The X component is a binary vector of length n so that x ∈ Z n 2 . In this case, x = 1110000, representing X 1 X 2 X 3 , where X i represents the operator which applies X to the ith qubit and I elsewhere. The Z component is a value z ∈ Z n 8 . In this case z = 0040000 representing T 4 3 . In terms of X and T operators, we can write: As the phase and Z components are divisible by 4, we can rescale A and write it as a precision 2 operator by dividing the phase and Z components by 4:

Multiplication Rule and Generalised Symplectic Product
In the Pauli stabiliser formalism, we represent operators as binary vectors and understand commutation relations in terms of the symplectic product. In this section, we generalise the symplectic product to the XP formalism, and this allows us to write a simple rule for multiplying XP operators. Let z ∈ Z n be an integer vector of length n with ith component denoted z[i]. The antisymmetric operator of precision N corresponding to z is: In this paper, arithmetic operations on vectors are component-wise in Z i.e.: We can then express the multiplication of two XP operators as the sum of their vector representations, adjusted by an antisymmetric operator: The product of two XP operators given in vector format is: Proof. For n = 1, looking at matrix representations of X and P we see that: From this, we can show that the multiplication rule applies for all single qubit XP operators in ωI, X, P and in turn to the tensor products of such operators.

Example 3.2 (Multiplication of XP Operators)
Let N = 4, n = 3 so that unique vector representations of XP operators are XP N (p|x|z) where (p|x|z) ∈ Z 8 × Z 3 2 × Z 3 4 . Consider two example XP operators A 1 and A 2 defined as Then This example is worked out in detail in the linked Jupyter notebook. You can also explore how multiplication works for random XP operators of arbitrary precision and length.

Other Algebraic Identities
We can write simple closed form identities for various algebraic operations in terms of antisymmetric operators, and these are summarised in Table 4. These identities allow us to efficiently implement algebraic operations in the XPF software package.

Example 3.3 (Algebraic Identities)
The following are some consequences of algebraic identities in Table 4: 1. The MUL and INV rules imply that products and inverses of diagonal operators are diagonal.
2. The SQ and COMM rules imply that squares and commutators of XP operators A, B are always diagonal.
3. The CONJ rule implies that conjugating an operator A by an operator B results in A times a diagonal operator.

Rule MUL
Multiplication of two XP operators Square of an XP operator Inverse of an XP operator Action of an XP operator on a computational basis vector XP N (p|x|z)|e = ω p+2e·z |e ⊕ x

Group Structure of XP Operators
Because we have rules for products and inverses of XP operators, the XP operators of precision N on n qubits form a group, denoted X P N,n . For any set of XP operators G, we can determine the group generated by the operators which we denote G = G . The subset of diagonal XP operators G Z forms an Abelian subgroup. This is because diagonal operators commute and G Z is closed under multiplication (and so includes all inverses and the identity operator).
There is a natural group homomorphism Zp between G Z over multiplication and Z n+1 2N over addition modulo 2N . For diagonal operators, the action of Zp is: The Zp map is well defined and is a group homomorphism because: and so: The inverse map Zp −1 (z|p) = XP N (p|0|z/2) is well defined providing each component of z is divisible by 2 in Z 2N (even Z components). Addition over Z n+1 2N takes vectors with even Z components to vectors with even Z components. Hence, we can find the generators of G Z by finding a set of vectors B ⊂ Z n+1 2N which span Zp(G Z ). Using the Howell matrix form of Appendix A, we set B = How Z N (Zp(G)). The set Zp −1 (B) generates G Z . This method is used to determine a unique set of canonical generators for an XP group (see Section 4.1).

Eigenvalues and Projectors of XP Operators
Identifying the eigenvalues and eigenvectors of XP operators will be important when considering measurements. We first show how to determine the action of an XP operator on computational basis elements. The degree and fundamental phase of an XP operator, defined in this section, allow us to determine the eigenvalues of XP operators efficiently. These results are used in the chapters on identifying the codespace and measurements in the XP formalism (Chapters 4, 7).
The action of an XP operator on a computational basis element |e of H n 2 where e ∈ Z n 2 is: When calculating the action on computational basis elements, we apply the diagonal part of the operator first, then the X component. The notation e · z = i e[i]z[i] is the usual dot product for vectors in Z. The notation e ⊕ x = (e + x) mod 2 denotes component-wise addition modulo 2 which is equivalent to XOR for binary vectors e and x. For a given XP operator A, A 2N = I so there must be a minimal deg(A) ∈ Z 2N such that for some q ∈ Z 2N : We call deg(A) the degree of A and q the fundamental phase of A. The degree can be calculated efficiently via the method below:

Proposition 3.2 (Calculating Degree of Operator)
We calculate the degree of XP operator A = XP N (p|x|z) as follows: . We need to solve for mz = 0 mod N . To show 2, note that odd powers of A are non-diagonal, so the degree must be even. Apply 1 to A 2 which is diagonal.
Once we have the degree of an operator, the fundamental phase is the phase component of A deg(A) . Determining the fundamental phase and degree of an XP operator allows us to identify its eigenvalues, as follows: Proof. Let |ψ be an eigenvector with A|ψ = ω p |ψ . By the definition of degree and fundamental phase, A d = ω q I so A d |ψ = ω dp |ψ = ω q |ψ . Hence dp = q mod 2N and the result follows.
The following proposition allows us to calculate the action of projectors of XP operators on a computational basis element: Proposition 3.4 (Action of XP Projectors on computational basis elements) Consider the projectors A λ of A onto the λ-eigenspace of A. If A is diagonal, the action of A λ on the basis element |e is: If A is non-diagonal, the action of A λ is: Proof. To verify Eq. (23), note that where A 2 |e = λ 2 |e :

Calculating Codewords from Stabiliser Generators
In this section, we show how to identify the codespace stabilised by a given set of XP operators. In the Pauli stabiliser formalism, there is a very simple relationship between the number of stabiliser generators and the dimension of the codespace the stabiliser group defines. Given a stabiliser group on n qubits with k independent commuting generators, the codespace has dimension 2 (n−k) . In the XP formalism, this relationship is much more complex. For example, the eigenspace dimensions of XP operators vary widely and are not in general powers of 2. As an illustration of this complexity, the +1 eigenspace dimensions which arise for various 7-qubit diagonal XP operators of precision 8 are listed in Table 5. Readers can explore eigenspaces of diagonal XP operators in the linked Jupyter notebook.

Operator
Dim Operator Dim Operator Dim Here we present an algorithm to identify the codespace of a set of XP operators. The input for our algorithm is an arbitrary list of XP operators G ⊂ X P N,n . The output is a list of codewords {|κ i : 0 ≤ i < dim(C)} that form a basis for the codespace C stabilised by the group G = G , or an empty set if there is no codespace. The algorithm operates in two steps: 1. Convert the set of XP operators into a canonical form. This is a set of generators S in a particular form which generate the stabiliser group S = G . We split the canonical generators into diagonal S Z and non-diagonal generators S X , where the diagonal canonical generators S Z generate the diagonal subgroup of the stabiliser group.
2. Calculate an independent set of codewords |κ i that span the codespace. We do this by applying the orbit operator (defined below in terms of the S X ) to particular computational basis elements |m i in the simultaneous +1 eigenspace of the S Z .
We will describe these steps in detail in the following sections.

Canonical Generators of XP Groups
For any set of XP operators G, we can calculate a set of operators in canonical form that generate the same XP group as G. Specifically, we calculate an independent set of diagonal (S Z ) and non-diagonal (S X ) operators that generate G . The diagonal subgroup of G is generated by S Z . Proposition 4.1 sets out the form and properties of the canonical generators. The proposition uses the concept of a generator product which is defined as follows. The generator product of an ordered set of XP operators S = {S 0 , . . . , S m−1 } specified by a vector of integers a ∈ Z m is: 1. Let S X be the r × n binary matrix formed from the X-components of the S X . The matrix S X is in Reduced Row Echelon Form (RREF).
2. Let S Zp be the s × (n + 1) matrix with rows taken from the image of S Z under the Zp map of Section 3.4 (i.e. Zp(XP N (p|0|z)) = (2z|p)). The matrix S Zp is in Howell Form (see Appendix A).

For XP
The following properties hold for the canonical generators: Conditions 1-3 ensure the canonical generators are unique for a given set of operators, and so can form the basis of the test in Property 2. The entries of S Zp are from Z 2N which is in general a ring. The Howell matrix form is a generalisation of the RREF which gives us a canonical basis for the row span of a matrix over a ring. See Appendix A for a full description of the Howell matrix form and linear algebra over rings.
We briefly consider the implications of Properties 1 and 2. Let G be an XP stabiliser group. If there is an operator of form ω q I, q = 0 in G , the codespace is empty. Due to the Howell Property (see Section A.2), we can determine if this is the case by checking if ω q I ∈ S Z for some q = 0. This is a generalisation of the requirement that −I / ∈ G in the Pauli stabiliser formalism and the concept of admissible generating sets in the XS stabiliser formalism (see Ref. [18] on page 7). Going forward, we assume that XP codes are specified in terms of their canonical generators S Z , S X and that there is no element ω q I, q = 0 in S Z .
Because the matrices S X , S Zp are in echelon form, this imposes a natural ordering on S X , S Z . Property 1 states that we can write any G ∈ G as a product of the canonical generators where operators are applied in this order. It implies that S Z generates the diagonal subgroup of G because the diagonal subgroup is the set of operators where a = 0. Recalling Example 3.3, all commutators and squares of elements in G are diagonal and so are in S Z . Applying the results in Section 3 of Ref. [15], we can also determine the size of the group G once we have the canonical generator form.
In Appendix B, we demonstrate an algorithm for calculating the canonical generators and prove Proposition 4.1.

Finding a Basis of the Codespace
In this section, we will show how to find a basis of the codespace stabilised by the canonical generators S Z , S X of Section 4.1. The result is a set of independent codewords that span the codespace.
The codespace is the intersection of the simultaneous +1 eigenspace of the diagonal generators and the +1 eigenspace of the non-diagonal generators: The diagonal generators determine the Z-support of the codewords. We define the Z-support of a state |ψ in H n 2 as the set of length n binary vectors e such that the coefficient of the corresponding computational basis vector |e in |ψ is non-zero. That is: Because all elements in S Z are diagonal, we can write a basis of C Z as a set of computational basis vectors: Let E := ZSupp(C Z ) be the binary vectors corresponding to the computational basis vectors in C Z . Any codeword expressed in terms of the computational basis must be a linear combination over C of |e , e ∈ E. The non-diagonal generators determine the relative phases of the computational basis vectors in the codewords. The relative phase information is captured by the orbit operator. Let S X be the non-diagonal canonical generators {A i : 0 ≤ i < r} ordered as in Section 4.1. Using the generator product notation of Eq. (25), the orbit operator is defined as: Where e ∈ E, the image of |e under the orbit operator, O S X |e , is fixed by all elements of the stabiliser group S Z , S X (see Proposition C.1). In the next section, we demonstrate how to find an independent set of codewords of this form which span the codespace.

Coset Structure of E and Orbit Representatives
In this section, we assume we are given E, the Z-support of C Z as in Eq. (28), and show how to identify a subset E m of E such that the image of E m under the orbit operator is a basis of the codespace (i.e. an independent spanning set). The resulting basis is a set of un-normalised codewords |κ i such that: The normalisation constant is 1 √ 2 r where r is the number of non-diagonal canonical generators, and is omitted for clarity. Once we have E m , we know the dimension of the codespace: We identify the subset E m by looking at the coset structure of E. First, we show that the Zsupport of a codeword in the form of Eq. (30) can be viewed as a coset in the group Z n 2 under component-wise addition modulo 2. Let S X be the binary matrix formed from the X-components of the S X which is in RREF by construction (See Proposition 4.1). Then Span Z2 (S X ) = S X is a subgroup of Z n 2 of size 2 r where r = |S X |. The Z-support of O S X |e can be identified with a coset in the group of binary vectors Z n 2 : ZSupp(O S X |e ) = e + S X := {(e + uS X ) mod 2 : u ∈ Z r 2 } (32) Next, we introduce the residue function which tells us whether two vectors are in the same coset, and hence occur in the Z-support of the same codeword. Let m = Res Z2 (S X , e) be defined as: Two vectors e 1 , e 2 ∈ E are in the same coset if and only if Res Z2 (S X , e 1 ) = Res Z2 (S X , e 2 ). The residue of e is zero if and only if e ∈ S X . We use the residue function to identify a subset of E of minimal size whose image under the orbit operator yields a basis of the codespace. The set of orbit representatives E m is defined as the image of E under the residue function: The cosets of E m partition E (see Proposition C.3). Accordingly, the image of E m under the orbit operator is a basis of the codespace (see Proposition C.4).

Codewords Notation
The following notation for codewords is used throughout this paper. Let S X be the matrix formed from the X-components of the non-diagonal canonical generators S X . As S X is in echelon form, rows have a natural ordering and we interchangeably consider S X to be a set of binary vectors. Let S X have r non-zero rows or |S X | = r. The set of codewords generated from the orbit representatives is uniquely determined. When written in terms of the computational basis, we refer to the following as the orbit form of the codewords: The Z-support of the codewords is the same as the Z-support of C Z , the simultaneous +1 eigenspace of the S Z , and is denoted E: We can write a coset decomposition of E in terms of E m as follows: There is a direct relationship with the Z-support of each codeword as follows: In addition, there is a unique coset decomposition of E m so that E m = E q + L X for sets of binary vectors E q and L X so that E = E q + L X + S X . We demonstrate how to find this decomposition in Section 6.3.2. The full coset decomposition is useful for the following reasons: • The X-components of logical operators must be in L X + S X , and we can calculate a generating set of non-diagonal logical operators with X components in L X (Section 6.3.2) • The size of E q gives rise to a natural classification of XP codes (Section 6.5).
• We assign quantum numbers to each codeword (Section 6.4) based on the coset decomposition of E m which then allows us to analyse the logical action of operators (Section 6.7).

Calculating Orbit Representatives from the Canonical Generators
We have demonstrated that the image of the orbit representatives under the orbit operator is a basis of the codespace, and that the dimension of the codespace is given by the number of orbit representatives. In previous sections we have assumed that we have been given E, the Z-support of the simultaneous +1 eigenspace of the S Z , as a starting point. In practice, we generally start with the stabiliser generators of a code, and calculating E from them is an NP-complete problem for XP codes (see Ref. [18] Section VII).
In this section, we show how to calculate the orbit representatives from the canonical generators. Orbit representatives have a specific form which reduces the search space significantly compared to searching for the whole of E. We use a graph search algorithm to make finding the orbit representatives tractable for 'reasonable' codes.

Exhaustive Algorithm to find E
We first show how to find E using an exhaustive inefficient algorithm. Let Calculating the +1 eigenspace of S Z is equivalent to solving the following equation in binary vectors e: For this equation to have solutions in e, p i must be divisible by 2 in Z 2N . Let S Zp be the matrix with rows (z i |p i /2). Let (e|1) represent the column vector e with an entry of 1 appended. Eq. (39) can be written in matrix form as: Solutions are of form: where K is the Howell basis of Ker Z N (S Zp ) (see Section A.2). To find solutions for binary vectors e, we seek a ∈ Z n N such that (e|1) = aK mod N is a vector of zeros and ones. Linear algebra techniques cannot be used to find the vectors a. We would in principle need to search through all possible values of a to find valid solutions. Given that there are N |K| possible values of a, this is of exponential complexity.

Graph Search Algorithm for Orbit Representatives
Rather than searching through all possible values of a in Eq. (41) to find E, we employ a more efficient graph search algorithm which uses the special form of the orbit representatives to speed up the the search.
The special form of the orbit representatives is as follows. Let x j be the jth row of S X and let l j be the leading index of x j -i.e. x j [l j ] = 1 and x j [k] = 0, ∀k < l j . In Proposition C.5, we show that for any orbit representative m i ∈ E m , m i [l j ] = 0 for all leading indices l j , 0 ≤ j < |S X |. In each coset of S X , m i is the unique vector with this property. As S X is in RREF, there are exactly r = |S X | leading indices l j where m i [l j ] is guaranteed to be zero.
We modify the exhaustive search algorithm presented in Section 4.3.1 to take into account the special form of the orbit representatives: The search is made more efficient by storing and re-using partial solutions (dynamic programming) and results in a graph object from which the solutions can be generated. The main advantage over the exhaustive algorithm is due to the reduction of the search space by a factor of 2 r by using the special form of the orbit representatives. Where all stabiliser generators are diagonal and r = |S X | = 0, the advantage over the exhaustive algorithm is not as significant. However, for 'reasonable' codes which have both diagonal and non-diagonal generators, and which encode a relatively low number of logical qubits, the graph search algorithm is efficient in practice. It is possible that the search algorithm returns an empty set. In this case, the simultaneous +1 eigenspace of the S Z is empty and there is no codespace. In this case, the XP stabiliser group does not define a code.

Summary of Codewords Algorithm
In summary, the algorithm for identifying the codespace stabilised by an arbitrary set of XP operators G is: 1. Calculate the canonical generators S Z and S X such that G = S Z , S X using the algorithm in Section 4.1. If ω q I ∈ S Z for q = 0, the codespace is empty.

Example: Calculating Codewords -Code 1
We illustrate our algorithm to find the codewords with an example. We will use this same example throughout this paper to illustrate various concepts. The detailed calculations for this example are set out in the linked Jupyter notebook. We start with the following stabiliser generators of precision N = 8 on n = 7 qubits: Step 1: Canonical Generators Using the algorithm in Appendix B, the canonical generators for this code are: Note that a single diagonal generator yields multiple diagonal canonical generators. This behaviour is typical of XP groups.
Step 2: Orbit Representatives The graph search algorithm in Section 4.3.2 yields the following orbit representatives: The dimension of the codespace is dim(C) = |E m | = 4.
Step 3: Image of orbit representatives under orbit operator is a basis Finally, we form an independent set of codewords {κ i } by applying the orbit operator O S X of Eq. (29) to the computational basis elements corresponding to the E m : (46)

Calculating Codewords -Discussion and Summary of Results
Given a set of XP operators G, we can determine a basis for the codespace stabilised by G . We first determine a set of canonical generators using linear algebra techniques over rings (Section 4.1). The method uses the unique vector representation of XP operators of Section 3.1 and can be done efficiently. This mirrors the result for generalised Pauli groups in Ref. [11].
Once we have the generators in canonical form, we find the orbit representatives E m using a graph search algorithm (Section 4.3.2). The codespace dimension corresponds to the number of orbit representatives, and applying the orbit operator defined in Eq. (29) to the orbit representatives results in a basis of the codespace. The graph search algorithm works for any XP code, but its efficiency depends on the precision of the code and the number of non-diagonal stabiliser generators. In the worst case, where we have only diagonal stabilisers, finding the orbit representatives reduces to an NP-complete problem.

Classification of XP Stabiliser States
Now that we have some familiarity with the XP stabiliser formalism, it is natural to ask which quantum states can be represented within the formalism. In this chapter, we demonstrate an equivalence between XP stabiliser states and 'weighted hypergraph states' -a generalisation of both hypergraph [23] and weighted graph states [14].
In the Pauli stabiliser formalism, any stabiliser state can be mapped via local Clifford operators to a graph state [26]. In the XS Formalism [18], the authors show that the phases of an XS stabiliser state are described by a phase function which is a polynomial of maximum degree 3. In this chapter, we generalise these results to the XP formalism.
In Section 5.1, we introduce definitions for weighted hypergraph states. In Section 5.2, we describe the phases which are possible for XP stabiliser states. In Section 5.3, we show how to represent any XP stabiliser state as a weighted hypergraph state. Finally, in Section 5.4 we show how to represent any weighted hypergraph state as an XP stabiliser state. In general, this requires us to embed the weighted hypergraph state into a larger Hilbert space.

Weighted Hypergraph State Definitions
In this section, we introduce the concept of weighted hypergraph states -a class of states which includes graph, hypergraph and weighted graph states. A generalised controlled phase operator CP (p/q, v) is specified by a rational number p/q and a binary vector v of length r. The action of the operator on a computational basis state |e , e ∈ Z r 2 is: Multiplication of vectors in the above equation is component wise. We construct a weighted hypergraph state by applying a series of generalised controlled phase operators to the |+ ⊗r state.
In the Pauli stabiliser formalism, all stabiliser states can be mapped to graph states by applying a set of local Clifford unitaries. A graph state on r vertices is specified by a set of edges The graph state is formed by applying controlled Z operators corresponding to the edges to |+ ⊗r i.e. |φ = ( (i,j)∈E CZ ij )|+ ⊗r .
We now show how graph states generalise to weighted hypergraph states. For graph states, only phases of ±1 are possible as we apply controlled Z operators. Generalised controlled phase operators, on the other hand, can apply any phase of form exp(i2πp/q). Where p/q = 1/2, the operator acts as a generalised controlled Z operator because it applies a phase of

Phase Functions of XP States
In this section, we describe which relative phases are possible for XP stabiliser states. The phase function of an XP stabiliser state |φ of precision N is an integer valued function f on vectors e ∈ ZSupp(|φ ) such that: We generally consider f to be a function of the binary variables e i := e[i], 0 ≤ i < n. In this chapter, phase functions are defined by a vector q ∈ Z 2 n and are polynomials of form: For phase functions of this form, we can identify each term of the polynomial with a generalised controlled phase operator. The term q[s] j∈s e j corresponds to the controlled phase operator It is known that for Pauli stabiliser states (N = 2 = 2 1 ), the phase function is a polynomial of the form in Eq. (49) of degree at most 2 in the variables e i , whilst for XS codes (N = 4 = 2 2 ), the maximum degree is 3. Our aim is to generalise these results to XP codes. We first show how to express the Z-support of any XP stabiliser state in terms of a set of binary variables {u i }, which are a subset of the {e i } variables defined above. We will then express the form of the phase function of an XP stabiliser state in terms of the {u i }. Due to the results of Section 4.4, any XP stabiliser state can be written in the following canonical form: for non-diagonal canonical generators S X , r = |S X | and where m is the single orbit representative. The orbit operator O S X is defined in Eq. (29) and the generator product S u X is defined in Eq. (25).
We can write |φ in terms of the binary variables The sum in the above equation ranges over all possible values of u i ∈ Z 2 , for 0 ≤ i < r. The Z-support of |φ can be expressed in terms of the {u i } as follows: We (b) For N = 2 t , the maximum degree of the phase function is t + 1.
Proof of Proposition 5.1 is in Appendix D.

Representation of XP States as Weighted Hypergraph States
We now demonstrate a method for determining the phase function for a given XP state. This allows us to represent XP stabiliser states as weighted hypergraph states.

Method
1. Let l i be the leading index of x i and define the r × n binary matrix L by setting L ij = 1 if j = l i and 0 otherwise.
2. Let p be a vector whose entries are indexed by rows u ∈ Z r 2 such that p[u] is the phase component of S u X |m 3. For u in Z r 2 , ordered by weight then lexicographic order: If the precision N = 2 t is a power of 2, we only need to consider rows of weight at most t + 1 due to Proposition 5.1. By multiplying the 1 × r vector u by the r × n matrix L in step 3(a), we create a 1 × n vector v such that v[l i ] = u i .

Example 5.1 (Weighted Hypergraph Representation of XP State -Union Jack State)
The following example illustrates the operation of the algorithm to determine the phase function of an XP stabiliser state and hence the weighted hypergraph representation. For precision N = 4, let |φ = O S X |m with: Calculating the phase component of S u X |m for all values of u ∈ Z r 2 , we find that the phase is zero for all values of u, apart from u = 1011 and 1101 where the phase is −1.
The degree of f is 3, which is the maximum degree for states of precision N = 4 = 2 2 . We can write |φ as a weighted hypergraph state by applying CP (1/2, 1011000000) and CP (1/2, 1101000000) to e∈ZSupp(|φ ) |e . The state |φ is the unit cell of the 'Union Jack' state introduced in Ref. [17]. This is a hypergraph state with 2-dimensional Symmetry Protected Topological Order (SPTO) and is a universal resource for quantum computation using only single qubit measurements in the X, Y, and Z basis -see Figure 1. Detailed working for this example is available in the linked Jupyter notebook.

Representation of Weighted Hypergraph States as XP Stabiliser States
In this section, we show how to represent any weighted hypergraph state as an XP stabiliser state. In general, this involves embedding the state into a larger Hilbert space using an embedding operator. We first demonstrate this for a single generalised controlled phase operator i.e. |φ = CP (p/q, v)|+ ⊗r . There are two possible cases depending on the weight of the vector v.

Case 1 wt(v) = 1:
Let wt(v) = 1 and let i be the single non-zero component of v. For a given precision N , we can identify CP (1/2N, v) with the operator √ P = diag(1, ω) acting on qubit i because for a computational basis vector |e , √ P i |e = ω|e if e[i] = 1 and |e otherwise. Hence, to create a phase of exp( p q 2πi), we can let 2N = q. We also need N to be an integer ≥ 2 so we set N as follows:   The state |+ ⊗r is stabilised by This can also be written

Case 2 wt(v) ≥ 2:
For m := wt(v) ≥ 2, we in general need to embed the weighted graph state |φ into a larger Hilbert space to represent it as an XP stabiliser state. The embedding operator is defined in terms of M r m , the binary matrix whose columns are the bit strings of length r of weight between 1 and m inclusive. We order the columns of M r m first by weight then by lexicographic order. The embedding operator E r m acts on computational basis vectors as follows: Our aim is to find a precision N and a set of stabiliser generators S X , S Z which stabilise the embedded state |ψ := E r m |φ . We set the precision N = q2 m−2 -this is because phase function terms of degree m include a factor of 2 m−1 modulo 2N (see Proposition 5.1) and we need to allow for phases of form exp(2πi/q). If N is odd, we multiply it by 2 so that we can form the diagonal stabiliser generators (see Eq. (62) below).
The non-diagonal stabiliser generators S X determine the phase function and are defined as follows. The X-components of the S X are the rows x j of M r m . The Z-components are obtained by multiplying the x j by an 'alternating vector' a and an 'inclusion vector' w. The vector a is indexed by the columns u of M r m and is 1 if the weight of u is even, and −1 otherwise: The inclusion vector w with respect to v is: Multiplying the rows x j of M r m by the inclusion vector w ensures that we only consider columns of M r m whose support is a subset of the support of v. As a result of Proposition D.3, the following operators generate the required phase function: We now show how to construct the diagonal stabiliser generators S Z . We calculate a basis of Ker Z2 (M r m ) as follows. Because the columns of weight 1 occur first, M r m is of form M r m = I|A for some binary matrix A. Hence the kernel of M r m over Z 2 is spanned by: It is easy to see that K r m (M r m ) T mod 2 = 0. Let z j be the jth row of K r m so that x i · z j mod 2 = 0. The following operators commute with the elements of S X : This can be seen by using the COMM rule of Table 4 and noting that N x j · z j mod 2N = 0: We are now in a position to state the algorithm for weighted hypergraph states with multiple generalised controlled phase operators.

Algorithm: Representation of Weighted Hypergraph States as XP Stabiliser States
Output: A precision N , an embedding operator E r m and stabiliser generators S X , S Z of an XP code whose codespace is spanned by |ψ := E r m |φ , a state with the same phase function as |φ .

Method:
1. Let m = max({m i }) -we use the embedding operator E r m . Note that when m = 1, the embedding operator is trivial as M r 1 = I r . 2. We set the precision of the code as N := LCM(2, {N i }) where we define the N i as follows: 3. If m = 1, Ker(I r ) = ∅ so we do not require any diagonal stabiliser generators. For m > 1, the diagonal stabiliser generators are S Z := {XP N (0|0|N/2z j )} where z j is the jth row of K r m as in Eq. (61). 4. The non-diagonal stabiliser generators S X := {A j } are determined as follows: The algorithm can be optimised by only including qubits which for some operator A j has a non-trivial Z-component. In Proposition D.4, we show that we can further optimise for generalised controlled Z operators with p i /q i = 1/2 by replacing the factor ax j in step (b) by v i [j]a(x j − 1). This has the effect of clearing the Z-component of A j indexed by column v i of M r m . This implies, for instance, that we can represent graph states, which are created using CZ operators, with a trivial embedding.

Example 5.2 (Representing Weighted Hypergraph States as XP Stabiliser States)
In Ref. [13], an example of a weighted graph state is given which is a universal resource for measurement-based quantum computation; see Figure 1. The unit cell of this state is The weighted graph state |φ can be represented as an embedded state |ψ = E 4 2 |φ stabilised by the following XP code of precision N = 4 on 10 qubits: Using the optimised method of Proposition D.4 and deleting redundant qubits, we find a more compact representation on 6 qubits as follows: Detailed working for this example is available in the linked Jupyter notebook.

Discussion and Summary of Results
In this chapter we have shown an equivalence between XP stabiliser states and weighted hypergraph states. For any XP stabiliser state, we can write a weighted hypergraph representation and viceversa. A very wide range of states can be represented within the XP stabiliser formalism, including all weighted graph states and hypergraph states. These results may prove useful in implementing fault-tolerant versions of quantum algorithms. The Grover and Deutsch-Jozsa algorithms both employ real equally weighted (REW) pure states. In Ref. [23], the authors showed that each REW state has an associated hypergraph state. As we can represent any hypergraph state within the XP formalism, this could be an interesting application.

Logical Operators and the Classification of XP Codes
The objective of this section is to understand the logical operator structure of a given XP code. Our aim is to determine all XP operators that act as logical operators on the codespace ("logical XP operators"), and classify the logical actions that arise.
We start by setting out definitions for logical XP operators and introduce the notion of a phase vector which allows us to describe the logical action of diagonal operators (Section 6.1).
In the Pauli stabiliser formalism, the stabiliser group G is unique for a given codespace and a Pauli operator acts as a trivial logical operator if and only if it is an element of G . In the XP formalism, there may be many different stabiliser groups for a given codespace. In Section 6.2, we show how to find a set of XP operators M in the canonical form of Section 4.1 that generates the set of trivial logical XP operators and which uniquely defines the codespace.
In Section 6.3, we show how to find a set of non-trivial logical XP operators L which together with M generates all logical XP operators. Using the example of Reed-Muller codes, we show that in some cases Pauli stabiliser codes can be viewed more naturally as XP codes and that we can systematically determine all possible logical XP operators for such codes using our techniques. Figure 2 explains how the various groups described above relate to each other.
In Section 6.4, we show how to assign quantum numbers to the codewords of Section 4.4 based on the logical operator structure of the code. This in turn leads to a natural classification of XP codes into XP-regular and non-XP-regular codes, which we discuss in Section 6.5. We show that each XP-regular code can be mapped to a CSS code which has the same diagonal logical operators and similar non-diagonal logical operators.
The algorithms for determining the generators for the logical XP group require the codewords of Section 4.4 as input. In Section 6.6, we demonstrate modified algorithms which take the canonical generators and orbit representatives of Section 4.2 rather than the codewords as input. These methods are more efficient than using the codewords as a starting point.
In Section 6.7, we describe a framework for analysing the action of diagonal logical XP operators based on the codeword quantum numbers. We show how to determine all possible diagonal logical actions for a given code and how to calculate an operator with a desired logical action. In Section 6.8, we use this framework to classify diagonal logical XP operators into core and regular operators and demonstrate that complex logical operators arise in non-XP-regular codes.

Definitions: Logical XP Operators
The logical XP identity group, denoted I XP , is the group of XP operators that fixes all elements in the codespace C. The codewords {|κ i } of Section 4.4 are a basis of the codespace, so we use the following definition: In the Pauli stabiliser formalism, the logical identity group for a stabiliser code is the same as the stabiliser group for the code. In the XP formalism, this is not necessarily the case and we show an example of this in 6.1. Determining the logical identity group is non-trivial, so we present an algorithm to construct it which takes the codewords as input.
The logical XP group, denoted L XP , is the group of XP operators that preserves the codespace -that is, the set of XP operators A ∈ X P N,n such that A(C) = C. In the Pauli stabiliser formalism, an operator A is a logical operator if and only if it commutes with all the stabiliser generators. In the XP formalism, A is a logical operator if and only if the group commutator of A with any logical identity operator is in the logical identity group (see Proposition E.2).
The action of a logical XP operator A on the codewords {|κ i } can be described in terms of a vector f and a permutation π of the codewords as follows: The vector f ∈ Z dim C 2N is referred to as the phase vector and tells us which phase is applied by A to each codeword. The permutation π describes the non-diagonal action and π 2 = 1 (see Proposition E.1). We call a logical operator non-trivial if it is not a logical identity (i.e. A ∈ L XP \ I XP ). If the phase vector for a diagonal operator A is constant, say c, then the logical action of A is ω c I. A diagonal operator is trivial iff its phase vector is zero.

Determining the Logical Identity Group
We present an algorithm to construct the generators of the logical identity group for an XP code. This algorithm takes the codewords of the XP code, as in Section 4.4, as input. The result is a list of XP operators M in the canonical form of Proposition 4.1 that generate the logical identity group, or FALSE if the complex span of codewords is not the codespace of any XP code of precision N . Detailed proofs of the results in this section are found in Appendix E.
We first demonstrate how to find generators for the diagonal logical identity group, then turn to the non-diagonal generators.

Diagonal Logical Identity Group Generators M Z
Our algorithm for finding the diagonal logical identity group is as follows: 1. Let E be the Z-support of the codewords (as defined in Section 4.2.2) and let E M be the matrix formed by taking {(e|1) : e ∈ E} ⊂ Z n 2 × Z 2 as rows. We show that this algorithm produces a generating set of diagonal logical identity operators in Proposition E.3.

Non-diagonal Logical Identity Group Generators M X
We now set out the algorithm to find the non-diagonal generators, which consists of two steps: first, we find the X components of the generators; second, we find the phase and Z components that are consistent with the relative phases between the computational basis elements in the codewords.
Step 1: Identifying the X-Components. Let E i be the Z-support of the codeword |κ i as defined in Section 4.2.2. Take any element e i ∈ E i and let T be the binary matrix with rows formed from {e i ⊕ e : e ∈ E i }. Let S X = RREF Z2 (T ) and let m i = Res Z2 (T, e i ) using the residue function defined in Eq. (142). Verify that E i = m i + S X for each codeword. If not, return FALSE.
Step 2: Determining the Phase and Z-Components. We use linear algebra modulo N (see Section A.3) to find valid phase and Z-components for the generators identified in Step 1. Assume that the codewords |κ i are written in orbit form as in Eq. (35). For each x in S X we complete the following steps: We show that this algorithm produces a non-diagonal logical identity operator in Proposition E.6.

Properties of the Canonical Logical Identity Generators
The algorithm to find the logical identity generators take the codewords as input and results in a set of generators M in canonical form. Hence, the set M uniquely identifies the codespace. Any XP group stabilising the codewords is composed of operators that act as logical identities on the codespace and so is a subgroup of M . In Proposition E.14, we demonstrate an algorithm for determining M that does not require the codewords as input, and so results in a test for whether two sets of XP operators stabilise the same codespace. The logical identity algorithm can also be used to determine if a given quantum state is a stabiliser state of an XP code of precision N . We simply apply the algorithm -if it fails, the state is not a valid XP stabiliser state. If it succeeds, the set of operators M is a set of stabiliser generators for the state. The method can also be used for codespaces with dimensions greater than 1. We illustrate the algorithm for the logical identity generators using our main example: Taking the codewords calculated for the code in Example 4.5 as input, we find that the canonical generators of the logical identity group are: Compare these to the canonical generators: By definition, any stabiliser of the codespace is a logical identity so S X , S Z ⊂ M X , M Z . In this example, the diagonal generators S Z are not the same as M Z , but they have the same simultaneous +1 eigenspace. In all cases, S Z ⊂ M Z . For this example, we observe that none of the operators in M Z are in S Z , but all of the operators in S Z are in M Z . For example: The non-diagonal generators S X are the same as M X , up to a product of elements of M Z . Full working for this example is in the linked Jupyter notebook.

Determining the Logical Operator Group
We now present an algorithm that will identify the logical XP operator group of an XP code. This algorithm again takes as input the codewords of Section 4.4, and is similar to the algorithm for the logical identity group. The result is a list of XP operators L that generate the logical XP operator group together with M and ωI. Detailed proofs of these results are in Appendix E.
We first demonstrate how to find generators for the diagonal logical operator group, then turn to the non-diagonal generators.

Diagonal Logical Operator Algorithm
The following algorithm gives a list of operators L Z which together with ωI and M Z generate all diagonal logical XP operators. We assume we have the codewords {|κ i } in orbit form as in Eq. (35) expressed as a linear combination of computational basis elements |e ij . The key to finding the diagonal logical operators is to form a matrix from the binary vectors corresponding to the basis vectors for each codeword, and an index which indicates which codeword the vector is from: 1. For each e ij , let i be a binary vector of length dim(C) which is all zeros apart from the ith component which is 1.
2. Let E L be the matrix formed by taking (e ij |i) ∈ Z n 2 × Z dim(C) 2 as rows.

Determine the Howell basis
be a row of K L and let M Z be the matrix formed from the Z-components of the diagonal logical identity operators M Z of Section 6.2.1. Let K be the Howell basis of the matrix formed from the residue of each row of the z k over Z N with respect to M Z . 5. Let z k be a row of K and let B k = XP N (0|0|z k ). Then the set L Z = {B k } is a set of non-trivial diagonal logical operators which together with M Z and ωI generate all diagonal logical XP operators.
Note that the operator XP (1|0|0) = ωI is always a logical operator for any XP code -it has the effect of applying a phase ω to all codewords. By convention, we do not include it in L Z . We show that the algorithm produces a generating set of diagonal logical XP operators in Proposition E.4.

Non-diagonal Logical Operators
In this section, we demonstrate how to find a generating set of non-diagonal logical XP operators. We first show how to find the X-components of a generating set of non-diagonal logical operators. We then demonstrate how to find valid phase and Z-components for a logical operator with a given X component.
Step 1: Identifying the X-Components. Here, we identify the valid X-components for all non-diagonal logical operators by calculating a coset decomposition of the orbit representatives E m . In Section 4.2.1, we showed that we can write the Z-support of the codewords, E, in coset form E = E m + S X . We can decompose the orbit representatives themselves into cosets E m = E q + L X . To find the matrix L X and set of vectors E q , we use the following result: Given a set of binary vectors E m ⊂ Z n 2 there exists a unique binary matrix L X in RREF such that: T is a group under component-wise addition modulo 2 because x 1 , Finally, the residue function is an equivalence relation partitioning E m into cosets of L X .
We can think of T = L X as the group of all vectors x such that x ⊕ E m = E m . The Xcomponent of any logical XP operator must be in L X + S X because logical operators preserve the codespace. In Proposition E.8, we show that logical operators with X-components in L X together with L Z , S X , S Z and ωI generate the full set of logical XP operators.
Step 2: Valid Phase and Z-components. Assume that the codewords |κ i are written in orbit form as in Eq. (35). The algorithm for finding the phase and Z-components of the operators for a given x ∈ L X is as follows: 1. Let e ij = e ij ⊕ x, and let p ij be the phase of e ij in the codewords 2. Let p ij = (p ij − p ij ) mod 2N . For there to be a valid solution, for fixed i the p ij are all either even or odd. Let a i = p i0 mod 2 be an adjustment factor 3. Let p ij = (p ij − a i )/2 so that p ij ∈ Z N , and let p be the binary vector with the p ij as components such that E T L (z|q) mod N = p using linear algebra modulo N (see Section A.3). Then A = XP N (0|x|z) is a logical operator.
In Proposition E.5, we show that the above algorithm generates a valid logical operator with X-component x, or returns FALSE if this is not possible. The resulting operator is non-diagonal, but is not necessarily a logical X operator. For A to be a logical X operator, then A 2 should be a logical identity operator. Applying the SQ rule of Section 3.3, A 2 is diagonal. Hence we require A 2 ∈ M Z . We show how to adjust the phase and Z component to ensure this in Section E.8.

Examples: Logical Operators
We now illustrate this algorithm for the logical XP operator group for two example XP codes: The orbit representatives for Code 1 of Example 4.5 are given by Eq. (45). We calculate the coset decomposition of E m which gives us the X-components of the non-diagonal logical generators. Using the technique in Proposition 6.1, we find that L X has 2 rows and E q is of size 1: By adding elements of L X to any orbit representative m i , we can reach any other orbit representative m j . The logical operator group generators are: Full working for this example is in the linked Jupyter notebook. We look at the logical action of these logical operators in Example 6.9.

Example 6.3 (Logical Operators -Code 2)
We now introduce our second main example, which is the code given by the following canonical stabiliser generators: Using the graph search algorithm of Section 4.3.2, the orbit representatives for Code 2 are: The algorithm in Section 4.4 yields the following codewords: Calculating the coset decomposition of E m = E q + L X using Proposition 6.1 we find that L X contains only one row but E q has 4 elements: From the starting point m i , we can only reach orbit representatives m j = m i ⊕ 0011110 by adding elements of L X modulo 2. We could, however, apply a unitary U which permutes codewords as follows.
Let the codewords in orbit form be |κ i = 0≤j<2 r ω pij |e ij . Let k = (i + 1) mod 4 then U is the operator given by: U cannot, however, be written as an XP operator. Applying the algorithms in sections 6.3.1 and 6.3.2 we find the following generators for the logical XP group: Full working for this example is in the linked Jupyter notebook.

Example 6.4 (Reed Muller Codes)
In this example, we look at Reed Muller codes. These can be viewed as XP codes, and the algorithms of this chapter make it straightforward to determine their full logical operator structure. By varying the parameters of these codes, we show that they give rise to transversal logical operators at any level of the Clifford hierarchy.
We can write the 15-qubit Reed Muller code as a precision 2 code (i.e. using Pauli group operators) in terms of diagonal (S Z ) and non-diagonal (S X ) stabiliser generators: The logical operators for precision N = 2 are: We can rescale this code to be of precision N = 8 by multiplying the Z-components of the generators by 4. Applying the algorithm in Section 6.3, we find additional diagonal operators as follows: Note thatS † has an S operator on same qubits asX, whilstT † has a T operator on all 15 qubits. If we again rescale to precision N = 16, we do not obtain any additional logical operators. This suggests that the code has a 'natural precision' of 8.
In the XPF, the stabiliser group for a given codespace is not unique. We can write a more compact generating set of precision 4 operators that stabilise the same codespace. The operators are symmetrical in X and S and generate a different stabiliser group to those in Eq. (85): Note here that the X-components of the non-diagonal generators and the Z-components of the diagonal generators are the rows of the binary matrix M 4 4 as defined in Section 5.4. In Proposition E.9, we generalise this example and show the Reed-Muller code on 2 r − 1 qubits can be written as the codespace of a precision N = 2 r−2 code whose stabiliser generators are symmetric in X and P with X and Z-components the rows of the matrix M r r respectively. Pleasingly, this gives a self-dual set of stabiliser generators for all codes in this family. This generalises the known result for the Steane code, where r = 3 and N = 2. Furthermore, to stabilise the code space of n = 2 r − 1 qubits, we require only 2r stabilisers, a logarithmic scaling. The code has natural precision of 2 r−1 and a transversal logical diag(1, exp(2πi/2 r−1 )) operator.
You can explore which logical operators arise in codes with different parameters for Reed Muller codes in the linked Jupyter notebook.

Assigning Quantum Numbers to the Codewords
In this section, we demonstrate a natural way of assigning quantum numbers to the codewords of Section 4.4. This view of the codewords gives rise to a classification of XP codes (Section 6.5). It also allows us to develop more efficient algorithms to determine the logical operator group (Section 6.6) and to analyse the logical action of operators (Sections 6.7, 6.8).
The assignment of quantum numbers is based on the coset structure of the Z-support of the codewords E (see Section 4.2.2). Recall from Section 6.3.2 that L X is a set of binary vectors such that E m = E q + L X . Hence, we can write E in coset form as: We refer to E q as the core of the code. We can index elements of E by writing: We can assign quantum numbers to the orbit representatives m ∈ E m of Section 4.2.2 as follows: and these also apply to the codewords of Section 4.4: We refer to l as the Core Index, u as the Stabiliser Index and v as the Logical Index. The orbit distance is used to develop more efficient versions the logical identity and logical operator algorithms (see Section 6.6), and is defined as:  , v) where v is the Logical Index and l is the Core Index. In this case, the size of the core is 1, so the core index is the same for all codewords. The dashed lines group together vectors with the same orbit distance. The vectors with orbit distance 0, i.e. u = 0 and v = 0 correspond to the core E q . In this case, the size of the core is 4, so we need both the Logical Index and the core index to specify the codewords. These examples are illustrated in the linked Jupyter notebook.

Classification of XP Codes
In this section, we present a way of classifying XP codes into XP-regular and non-XP-regular codes.
The main result is that each XP-regular code can be mapped via a diagonal unitary operator to a CSS code that has a very similar logical operator structure. We will see in Section 6.8 that non-XP-regular codes have a much richer logical operator structure that is distinct from PSF codes and so offer the possibility for interesting new classes of codes. In Section 6.5.1, we introduce the concept of XP-regular codes and give some examples and elementary properties. In Section 6.5.2, we demonstrate that each XP-regular code can be mapped to a CSS code with identical diagonal logical operators, and similar non-diagonal logical operators.

Definition of XP-Regular and Non-XP-Regular Codes
Consider an XP code, and let E q be the core of a code as defined in Section 6.4. If |E q | = 1, the code is XP-regular. Otherwise, the code is non-XP-regular.
One major difference between XP-regular and non-XP-regular codes is the codespace dimension. The codespace dimension for an XP code is dim(C) = |E q |2 k where k = |L X | (see Section 6.4). For an XP-regular code, |E q | = 1 so the codespace dimension is a power of 2 and it encodes k logical qubits. The codespace dimension of non-XP-regular codes may or may not be a power of 2. Non-XP-regular codes are not additive, and their structure resembles that of the codeword stabilised (CWS) quantum codes of Ref. [7]. The CWS class is very broad and includes all Pauli stabiliser and qudit stabiliser codes. There are examples of CWS codes which have better error correction properties than any known additive code with the same number of physical qubits. [21].
In Ref. [18], a 'regular code' is defined as one where the diagonal stabiliser generators of the code are elements of −I, Z ⊗n . All regular codes are XP-regular and in Section 6.5.2 we will show a link between the two definitions. The examples below illustrate our definition of XP-regular codes: 4. Code 2 of Example 6.3 is non-XP-regular, as |E q | = 4;

Mapping XP-Regular Codes to CSS Codes
In this section, we show that each XP-regular code can be mapped via a diagonal unitary operator to a CSS code with a very similar logical operator structure. This is significant because it shows that the logical operator structure of an XP-regular code is no more complex than the corresponding CSS code. The algorithm for mapping a regular code whose canonical generators are S X , S Z is: 1. Determine a set of diagonal Pauli operators R Z with the same simultaneous +1 eigenspace as the S Z

If
3. The mapped CSS code has stabiliser generators R X , R Z .
We first show how to calculate a set of diagonal Pauli operators R Z which have the same simultaneous +1 eigenspace as S Z . This links to the definition of 'regular code' in Ref. [18], where regular codes were defined as those in which all diagonal generators are diagonal Paulis and implies that all 'regular codes' are XP-regular.

Lemma 6.2 (Regular Diagonal Generators)
If a code is XP-regular with diagonal canonical stabilisers S Z , then there exist diagonal Pauli operators whose simultaneous +1 eigenspace is the same as S Z .
Proof. If the code is XP-regular, it has core size 1. Let q be the sole element in the core. The Z-support of the simultaneous +1 eigenspace of the S Z can be written as: Let G X be the matrix formed from the rows of L X and S X . The rows of G X are independent. Find the Howell basis K of Ker Z2 (G X ). Because there are |S X | + |L X | = r + k independent rows in G X , there are n − r − k independent rows in K. , 0, z) : z ∈ K} and let the Z-support of the simultaneous +1 eigenspace of the R Z be E . Operators in R Z stabilise all elements e ∈ E so E ⊂ E .
Because R Z has n − k − r independent diagonal Pauli operators, |E | = 2 r+k = |E|. Hence the simultaneous +1 eigenspaces of S Z , R Z are the same.
We are now in a position to prove the main result of this section: Proposition 6.3 (Mapping XP-Regular Codes to CSS Codes) Given a XP-regular code C with canonical generators S X , S Z , there is a mapping to a CSS code C with generators R X , R Z such that: 1. If |κ i = 0≤j<2 r ω pij |e ij is codeword of C then |κ i = 0≤j<2 r |e ij is a codeword of C ; 2. C has the same diagonal logical operators as C; 3. If XP N (p|x|z) is a non-diagonal logical operator of C, then XP N (0|x|0) is a logical operator of C .
Proof. Let S X and S Z be the canonical generators for C. Because C is XP-regular, by Proposition 6.2 we can find a decomposition E = q + S X + L X and R Z which from −I, Z ⊗n and which have the same simultaneous +1 eigenspace as the S Z . Let R X = {XP N (0|x|0) : x ∈ L X } and let C be the code defined by the stabiliser generators R X , R Z . By construction, the simultaneous +1 eigenspaces of the diagonal generators are the same (and so are the respective Z-supports i.e. E = E ). The matrices formed from the X-components of the non-diagonal canonical generators are the same (i.e. S X = R X ). Hence, the orbit representatives are the same (i.e. E m = E m = {m i }), and so |κ i = O R X |m i = j |e ij form a basis for the codespace of C .
The algorithm for computing the diagonal logical operators in Section 6.3.1 depends only on the Z-support of the codewords. As E = E, the diagonal logical operators are the same.
In Section 6.3.2, we showed that the X components of the logical operators depend only on E = E , so for any logical operator XP N (p|x|z) of C, XP N (0|x|0) is a logical operator of C .
We can transform the codespaces C to C by applying the diagonal unitary U specified by: Example 6.8 (Map XP-Regular Code to CSS -Code 1) Code 1 of Example 4.5 is an XP-regular code. Applying Proposition 6.3 regular generators are given by: Full working for this example is in the linked Jupyter notebook.

Error Correction for XP-Regular Codes
We now briefly consider error correction for XP codes. One of the complexities associated with this problem is that the stabiliser generators of XP codes are not guaranteed to commute, so simultaneous measurements may not be possible. A possible error-correction routine for XPregular codes is as follows. In this case, we calculate the regular diagonal generators R Z which are diagonal Pauli operators. By measuring the R Z first and correcting for errors, we guarantee that we are in a subspace where all stabiliser generators commute and can complete the error-correction process by measuring the non-diagonal generators S X . A similar process is outlined in section V of Ref. [18]. Another approach would be to adopt the error correction methods for codeword stabilised (CWS) quantum codes presented in Ref. [7]. In this approach, the codewords of a Pauli stabiliser code are viewed as translations of a graph state |S by tensors of Pauli Z operators XP 2 (0|0|w i ). The vectors w i are called word operators and form a classical code over Z n 2 . Any single-qubit error can be propagated along the edges of the graph state by applying stabilisers of |S and converted into a tensor of Pauli Z operators XP 2 (0|0|z). This allows decoding using classical techniques using the bit string z. To use this approach, we would need to be able to convert an arbitrary XP code into a graph state translated by tensors of Pauli Z operators. We have seen in Chapter 5 that XP states can be represented as weighted hypergraph states. The orbit representatives E m of XP codes play a similar role to the word operators of CWS codes so this approach may have potential.

Modified Logical Operator Algorithms
The logical identity and logical operator algorithms presented in sections 6.2 and 6.3 require as input the codewords in the orbit form of Eq. (35). In the Pauli stabiliser formalism, there are algorithms for determining the logical Z and X operators that do not require us to first calculate the codewords. Can we find such algorithms in the XP formalism?
In this section, we demonstrate modified algorithms for determining the logical operator group which do not require the codewords as input. Instead, we take the the canonical generators and orbit representatives of Chapter 4 as a starting point. We show that the modified logical identity algorithm is significantly more efficient than the original version. As a result, the modified algorithm can be used to determine if two different XP groups have the same codespace.

Modified Logical Identity Algorithm
The modified algorithm for determining the logical XP identity group generators can be used where the precision of the code is a power of 2. The logical identity algorithm uses the Z-support E of the codewords (see Section 4.2.2). If N = 2 t , we only need to consider elements of E at most orbit distance t from the core (see Section 6.4, Proposition E.14).
The main steps of the modified algorithm are as follows.
1. Given a set of generators G for the stabiliser group, we calculate the canonical generators S and orbit representatives E m (see Chapter 4).
2. From S, E m , we can efficiently calculate E q , S X and L X without calculating E in full.
3. The elements of E at most orbit distance t from the core are E t = {(q + uS X + vL X ) mod 2 : We can then use E t instead of E to determine M in the algorithm set out in Section 6.2.
Next, we look at the computational complexity of the modified logical identity algorithm versus that of the original version. Let the coset decomposition of E = E q + S X + L X as in Eq. (89). The number of elements in E is |E| = q2 k+r where q = |E q |, r = |S X |, k = |L X |. Hence, the complexity of the original logical identity algorithm, which requires us to perform row operations on a matrix of size |E|, is O(q2 k+r ).
We now consider the computational complexity of the modified logical identity algorithm for codes of various precisions. For PSF codes, N = 2 = 2 1 and we only need to consider elements of E 1 which are at most orbit distance 1 from the core to find the logical identity group. The total number of elements to consider is q + q(k + r). Because q = 1 for all Pauli stabiliser codes, the run time of the modified algorithm is O(k + r) in this case.
For XS stabiliser codes, N = 4 = 2 2 . We need to consider elements of E 2 which are up to orbit distance 2 from the core. Hence, the logical identity algorithm is O(q + q(k + r) + q k+r 2 ) = O(q(k + r) 2 ) In general, we see that for precision N = 2 t , the modified logical identity algorithm is O(q(k + r) t ). For small N and large r or k, this can result in significantly faster run time compared to the original version which is O(q2 k+r ). Topological codes tend to have a small number of logical qubits but a large number of stabiliser generators, so this is an important improvement. We can also express the complexity in terms of the number of qubits n as O(n t ) because 2 n ≥ |E| = q2 k+r .

Modified Logical Operator Algorithm
Similarly, we can use a modified version of the logical operator algorithm where the precision of the XP code is a power of 2 (say N = 2 t ). Instead of calculating the codewords, we only need to consider the elements of E up orbit distance t from the orbit representatives E m . Proof of this claim is in Section E.4.

Diagonal Logical Actions Arising in an XP Code
In the Pauli stabiliser formalism, methods exist to find the logical Z operators for a code. In the XP formalism, a code may have logical operators with a wider range of actions -for instance, logical S, T or √ T operators, as well as logical controlled phase operators -for example logical CZ, CCZ and CT operators. In this section, we show how to describe all possible logical actions a diagonal logical operator can apply for a given code. We show how to determine whether a particular logical action is possible, and if so how to calculate a logical operator with this action.
We first show how to describe all possible actions which can be applied by the diagonal logical operators of a code. We use the phase vectors of Section 6.1 to describe the logical action of a diagonal operator. Let L Z be the set of diagonal logical operators plus ωI -the logical operator that applies a phase of ω to each codeword. Let F Z be the matrix whose rows are the phase vectors of L Z . We can calculate the Howell basis F D = How Z 2N (F Z ) by using the techniques in Appendix A so that F D = U F Z for some matrix U . The phase vectors which can be applied by a diagonal logical operator of the code are given by Span Z 2N (F D ).
We next show how to find a logical operator whose action is given by a phase vector in Span Z 2N (F D ). Let f i , u i be rows of F D , U respectively. Then the operator L i = L ui Z has the logical action given by f i , using the generator product notation of Eq. The action of operator XP 8 (4|0|0006266) is to apply ω 8 = −1 to the second codeword only. As we have two logical qubits, this is a logical CZ operation. In fact, the logical effects we can obtain are generated by ωI, and CZ on logical indices 01, 10 and 11. We can make combinations of these operators to generate the Z operators on the first and second logical qubit:Z The logical Z operator on the single logical qubit is: Full working for these examples is in the linked Jupyter notebook.

Example 6.10 (Logical Action -Hypercube Codes)
In Example 6.4, we saw that the Reed Muller code on 2 r − 1 qubits has a transversal logical diag(1, exp(i2π/2 r−1 ) operator. In this example, we view the Hypercube code of dimension D as an XP code of precision N = 2 D . We show that it has transversal generalised controlled Z logical operators at the (D − 1)st level of the Clifford hierarchy. This fact was first pointed out in Ref. [6], but is easily verified using the techniques of this section and we calculate the corresponding XP operators in the linked Jupyter Notebook.

Classification of Logical Operators
We now introduce a classification scheme for diagonal logical operators based on the quantum numbers assigned to the codewords in Section 6.4. A regular XP logical operator is an XP operator that applies the same phase to codewords with the same logical index. A core logical XP operator is an XP operator that applies the same phase to codewords with the same core index.
To determine if an operator is regular or core, we reshape the phase vector for the operator so that rows correspond to codewords with the same logical index and columns to codewords with the same core index. One might think that all logical operators are either core operators, regular operators, or products of core and regular operators. However, the operator C is a counterexample to this hypothesis and demonstrates that more complex logical operators arise in non-XP-regular codes. The operator C applies a phase of −1 when the core index is 0 and the Logical Index is 1. Because it applies a phase of −1 to one of the 8 codewords, the operator can be thought of as a CCZ gate. Full working for these examples is in the linked Jupyter notebook.

Logical Operators -Summary and Discussion
In this chapter, we have shown how to determine the logical operator structure for any XP code. We have presented algorithms to calculate generators for the logical operator and logical identity groups using linear algebra techniques (Sections 6.2 and 6.3). In contrast to the Pauli and qudit stabiliser formalism, XP codespaces are not uniquely identified by the stabiliser group. Two XP codes have the same codespace if and only if they have the same logical identity generators. The efficiency of these algorithms depends on the precision N of the XP code. Where N = 2 t , the algorithms are of O(n t ) complexity where n is the number of qubits (see Section 6.6). In the worst case, we need to determine the codewords in full to determine the logical operator group.
By allocating quantum numbers to the codewords, we can analyse the logical action of diagonal XP operators and fully classify which logical actions arise. We can determine all possible logical actions applied by operators of XP form, which can include logical operators at various levels of the Clifford hierarchy. These techniques give a more complete picture of the logical operator structure than previous methods, even when looking at Pauli stabiliser codes.
The coset decomposition of the orbit representatives E m yields the core E q of the code (Section 4.2.1), and allows us to determine the non-diagonal logical operators. The size of the core E q leads to a classification of XP codes into XP-regular and non-XP-regular codes. Any XP regular code can be mapped to a CSS code which has a similar logical operator structure via a unitary transformation. Non-XP regular codes have a more complex logical operator structure. Though not fully developed in this paper, there appear to be several possible approaches for error-correction of XP codes, despite the fact that stabiliser generators do not commute in general.
The main limitation of the above algorithms is that we consider only logical operators of XP form. An area for further investigation would be to develop algorithms to find the non-XP unitary operators which act as logical operators.

Measurements in the XP Formalism
Determining the extent to which computations on a quantum computer can be classically simulated is one of the central questions in the field of quantum information. In the Pauli stabiliser formalism, the Gottesman-Knill theorem states that stabiliser circuits can be classically simulated efficiently. In particular, given a Pauli stabiliser code, we can efficiently simulate the measurement of any Pauli operator on the codespace, including both exact calculation of the Born rule probabilities for such measurements as well as the update rule to determine the post-measurement state. In this chapter, we look at whether a similar result holds in the XPF -i.e. can the measurement of XP operators can be simulated efficiently in the XPF?
In Section 7.1, we set out our assumptions and criteria for an XP operator to be 'XP-measurable' on an XP code. In Section 7.2, we show how to determine the outcome probabilities for measurement of arbitrary XP operators on an XP codespace. In Section 7.3, we present an efficient stabiliser algorithm for measuring diagonal Pauli operators on XP codes. We consider whether we can do the same for precision 4 diagonal XP operators in Section 7.4 and show that estimating outcome probabilities is not tractable for these. We also give examples showing that the measurement of some XP operators takes us outside the XP formalism.

Measurement Definitions
We first define what we mean by an operator being measurable within the XP formalism.
Let C be an XP code with canonical stabiliser generators S. Assume the system is described by the density operator ρ which is proportional to the projector onto the codespace defined by S. We can write ρ in terms of the codewords and the Z-support E of the codewords of Section 4.2.2 as follows: Let A be an XP operator, and A λ the projector onto the λ eigenspace of A. The operator A is XP-measurable on C if for each eigenvalue λ of A: 1. We can calculate the probability of obtaining outcome λ which is given by Pr(λ) = Tr(A λ ρA λ ); and 2. We can find a set of XP operators S λ such that the projector onto the codespace defined by S λ is proportional to A λ ρA λ .
Note that in the above definition, we are only concerned with whether the above tasks can be done in principle, not whether they can be done efficiently.

Outcome Probabilities for Measurements of XP Operators
In this section, we demonstrate how to calculate the outcome probabilities for measurement of arbitrary XP operators on an XP code. We assume that we are given the codewords in orbit format as input (as in Eq. (35)).
For diagonal operators, we can calculate the outcome probabilities by looking at the Z-support of the codewords E (see Section 4.2.2). Let A be the diagonal XP operator we wish to measure and assume it has +1 as an eigenvalue. Let E + be the set of binary vectors E + = {e ∈ E : A|e = |e }. We show in Proposition F.1 that the probability of obtaining outcome +1 when measuring A is Pr(+1) = |E + | |E| . We can also calculate outcome probabilities for non-diagonal operators if given the codewords. The method is set out in Proposition F.2 and is somewhat more complex than for diagonal XP operators.
Hence, given the codewords, we can in principle determine the outcome probabilities when measuring any XP operator. This does not necessarily mean that the probabilities can be estimated efficiently or that we can express the resulting state of the system as an XP code as we see in Section 7.4

Stabiliser Method for Measurement of Diagonal Pauli Operators
We now consider the measurement of diagonal Pauli operators -i.e. elements of −I, Z ⊗n . In this special case, we can estimate the outcome probabilities efficiently and we can always express the resulting state as an XP code.
In this section, we demonstrate an efficient, stabiliser-based update algorithm to simulate measurements of diagonal Pauli operators. The algorithm provides update rules for the core form of an XP code after measurement. We first describe the core form of an XP code. We then state the algorithm for measuring diagonal Pauli operators and give some examples which illustrate the algorithm.

Core Form of an XP Code
In Ref. [1], measurements are simulated by determining update rules for the stabiliser generators, logical Z operators, logical X operators and anti-commutators.
Our algorithm gives update rules for XP codes in core form. The core form of an XP code consists of the following data: the core E q , which was introduced in Section 6.4 and is a set of binary vectors; the non-diagonal canonical generators S X of Section 4.1; and the logical X operators L X -of Section 6.3.2.
The core form encapsulates the key properties of the code in a compact way. From E q , S X and L X we can generate the orbit representatives and the codewords (see Section 6.4). If necessary, we can efficiently calculate the diagonal logical operators and logical identities using the algorithms in sections 6.2 and 6.3.

Algorithm for Measuring Diagonal Paulis
Assume we have an XP code in core form (i.e. the non-diagonal stabiliser generators S X generating non-diagonal logical operators L X and core E q as in Section 7.3.1). As per our discussion in Section 3.1, if the precision of the code N is not a multiple of 2, then Z operators do not exist. We can if necessary re-scale the code to be of precision 2N by doubling the phase and Z components of all stabiliser generators. Assume we wish to measure the diagonal Pauli operator A = XP 2 (0|0|z). Note that A has zero phase component but the algorithm can be generalised to operators with non-trivial phase components very easily. Our aim is to determine an XP code in core format representing the post-measurement system, as well as the probability of measuring each eigenvalue of A (in this case, ±1).
The algorithm uses the parity function of a binary vector x with respect to the binary vector z which is defined as: Par z (x) := x · z mod 2 (108) Step 1: Determine if there exists B ∈ S X or failing that, B ∈ L X with X-component x such that Par z (x) = 1. If B does not exist, go to Step 2. If B exists, we update S X ∪ L X and E q via the following steps: • For any C ∈ S X ∪ L X with X-component y such that Par z (y) = 1, replace C with BC.
Step 2: Split E q into two sets: The probability of obtaining the outcome +1 is Pr(+1) = |E + q | |Eq| and the post-measurement core is E + q . The probability of obtaining −1 is Pr(−1) = |E − q | |Eq| and the updated core is E − q .
In Appendix F, we explain in detail why the algorithm works. Essentially this is because the parity function of Eq. (108) commutes with the addition of vectors modulo 2. Once we have the code in core format, the above algorithm simulates measurement of diagonal Paulis in O(|E q | + |S X | + |L X |) time complexity.
The algorithm generalises the method of simulating measurements in the Pauli stabiliser formalism (e.g. in Ref. [1]). When simulating measurements in the Pauli stabiliser formalism, we look for stabiliser generators which do not commute with the operator being measured. The parity function serves a similar purpose in our algorithm. Any operator B with X-component x commutes with A if Par z (x) = 0 and anticommutes otherwise. Any computational basis vector |e with Par e (x) = q is in the (−1) q eigenspace of A. In Step 1, we need to remove at most 1 non-diagonal operator from S X ∪ L X , which is also the case for the Pauli stabiliser formalism.
One significant difference between the XPF and the Pauli stabiliser formalism is the possible outcome probabilities which arise. In the Pauli stabiliser formalism, outcome probabilities are always a multiple of 1 2 when measuring a single operator. This is not the case in the XPF because for non XP-regular codes, the sizes of E q , E + q and E − q may not be powers of 2. Outcome probabilities in the XPF may be irrational numbers -in particular when measuring non-diagonal operators (see Proposition F.2).

Examples -Measurement of Diagonal Paulis
Below are examples of the measurement of diagonal Paulis for Code 2 of Example 6.3 to illustrate the operation of the algorithm. Full working for these examples is in the linked Jupyter notebook. Example 7.1 (No update to S X ∪ L X -Code 2, Non-XP-Regular Code) Code 2 expressed in core form is: In this example, we measure A = XP 2 (0|0000000|0111111). Looking at elements of S X ∪ L X , the parity of all operators is 0, so we do not need to update them in Step 1 of the algorithm. Moving to Step 2, we calculate E + q , E − q as follows: The probability of measuring +1 is Pr(+1) = |E + q |/|E q | = 1/4, whilst the probability of measuring −1 is Pr(−1) = |E − q |/|E q | = 3/4. These probabilities do not arise when measuring a single operator in the Pauli stabiliser formalism. Example 7.2 (Update S X ∪ L X -Code 2, Non-XP-Regular Code) In this example, we measure A = XP 2 (0|0000000|0000100) on Code 2.
For Step 1, we find for B = XP 8 (12|1111111|0334567) the X-component x = 1111111 has parity +1. We remove B from S X . In L X , we also find C = XP 8 (14|0011110|0012340) with X-component y = 0011110 has parity 1. Replace C with BC = XP 8 (14|1100001|0700003). Update E q by adding x ⊕ q for q ∈ E q to E q so the updated code in core format is: We obtain measurement outcomes +1 or −1 with equal probability of 1 2 . This is always the case when we update S X ∪ L X in Step 1 because for the binary vector q, exactly one of q, q ⊕ x has parity +1.

Measuring Precision 4 XP Operators
In the previous section, we showed that diagonal Paulis are XP-measurable on any XP code. In this section, we look at the measurement of precision 4 XP operators, which can be considered the next most complex case. We show that determining the outcome probabilities for diagonal precision 4 operators is in general computationally complex. We look at two examples which illustrate that precision 4 XP operators are not in general XP-measurable because the post-measurement states cannot be expressed as an XP codespace.

Estimating Outcome Probabilities of Diagonal Precision 4 Operators is Intractable
Consider measuring a diagonal precision 4 XP operator A = XP 4 (0|0|z). The probability of obtaining outcome +1 when measuring A is |E + | |E| where E is the Z-support of the pre-measurement codewords and E + = {e ∈ E : A|e = |e } (see Proposition F.1). Hence, determining probability outcomes reduces to the problem of finding the simultaneous +1 eigenspace of the XP operators S Z ∪ {A}. Now consider simulating measurements on an XP code stabilising |+ ⊗m for some large value of m. Assume we have a series of diagonal XP operators A i of precision 4 which all share +1 as an eigenvalue. Proposition F.1 states that the probability of obtaining the result +1 after measuring the series of operators depends on the dimension of the simultaneous +1 eigenspace of the A i . Determining E + is known to be an NP-complete problem [18]. No matter which algorithm we use, we must calculate |E + | so this complexity seems unavoidable in the general case.

XP Formalism is not Closed under Measurement of XP Operators
The following examples illustrate that when measuring precision 4 operators, it is not always possible to represent the post-measurement system as the codespace of an XP code. Full working for these examples is in the linked Jupyter notebook:

Example 7.3 (Measurement of Diagonal Precision 4 Operator)
Let us measure the diagonal operator A = S 1 S 3 2 S 3 3 on the code defined by the stabiliser generators S X = {X 1 , X 2 , X 3 }, S Z = ∅ where X i denotes the Pauli X operator applied to the ith qubit. The codespace is one dimensional and spanned by |κ = |+ ⊗3 .
The operator A has 4 eigenvalues, with Z-supports of the corresponding eigenspaces as follows: The probability of obtaining each measurement result is: In the case of outcome +1, the post-measurement state is In Section 4.2.1, we demonstrated that the codewords of XP codes have Z-support of size 2 r for some integer r so this state cannot be written as the codespace of any XP code.
Similarly, for non-diagonal precision 4 operators, we can easily find examples of operators where the post-measurement system cannot be represented as the codespace of an XP code:

Measurement in the XP Formalism -Summary of Results
We have demonstrated that it is not in general possible to efficiently simulate measurement of XP operators in the XP formalism, apart from the special case of measuring diagonal Pauli operators. Firstly, measurement of an XP operator on an XP code may result in a state which cannot be described as an XP codespace. We have seen two examples which illustrate this. Secondly, calculating outcome probabilities when measuring a series of diagonal operators requires us to determine the simultaneous +1 eigenspace of these operators. This is known to be an NP-complete problem when the operators are of precision 4.
Hence, there appears to be no obvious generalisation of the Gottesman-Knill theorem to XP codes. This suggests that XP codes can describe states which display computationally complex, non-classically simulable behaviour.

Discussion and Open Questions
In this paper, we have set out the foundations for the XP formalism. We have formulated XP versions of many of the algorithms available in the Pauli stabiliser formalism -for instance determining a basis for the codespace, generators for the logical operator group and simulating the measurement of diagonal Pauli operators. The computational complexity of these algorithms depends on the precision N of the XP code, and certain edge cases have exponential complexity. We have given examples of XP operators which cannot be measured within the formalism or where estimating outcome probabilities is NP-complete. Hence, there appears to be no obvious generalisation of the Gottesman-Knill theorem to XP codes. XP codes are on the boundary of what is classically simulable, and so there are good reasons to believe that XP codes allow us to engineer states which exhibit useful, non-classically simulable behaviour.
The rich logical operator structure of XP codes may make them useful for applications such as magic state distillation, which requires codes with non-Clifford logical operators. In Ref. [22], the authors showed that triorthogonal CSS codes have optimal error correction parameters for Pauli stabiliser codes with a transversal logical T operator. We note that this result only applies to XP codes of precision 2, and in particular does not apply to non-XP-regular codes. XP codes with transversal logical non-Clifford operations (for instance T or CCZ gates) could be used for fault-tolerant preparation of magic states. We have focused so far on XP codes where the precision is a power of 2. Where the precision is not a power of 2, XP codes may have logical operators which are outside the Clifford hierarchy.
We have described the states and phase functions which arise within the XP formalism. As part of this, we have shown that two important classes of states, hypergraph and weighted graph states, can be represented as XP stabiliser states. Hence, we can use the algorithms presented in this paper to analyse these. One of the main benefits of looking at them as XP stabiliser codes is that we can very easily determine the symmetries of the states as these are just the elements of the logical identity group. In Figure 3 and the the linked Jupyter notebook, we illustrate how the algorithms in this paper make it easy to determine the Z 2 symmetries of the Union Jack state of Ref. [17].
(a) Stabiliser Generators for Union Jack State: Using the techniques in this paper, we can represent the Union Jack State as an XP code. This makes it easier to study the Z 2 symmetries of the state. In this figure, we illustrate a sample set of stabiliser generators for the XP code. There are qubits on each vertex and each edge of the cellulation. The different coloured dots represent the application of operators for the stabiliser generator as follows. Grey: X; yellow Z; red S; blue: S 3 .
(b) Onsite Symmetry for Union Jack State: By multiplying together all non-diagonal stabiliser generators, we find an onsite symmetry which is preserved apart from a phase component on certain qubits on the boundary. This is indicative of symmetry protected topological order. In the linked Jupyter notebook, we show that there are 3 onsite symmetries for the Union Jack state on a square plane with open boundary, two of which are are preserved on the lattice and one which is not. In the Pauli and qudit stabiliser formalisms, operators commute up to a phase. In the XP stabiliser formalism, operators commute up to a diagonal operator. This suggests that non-Abelian anyon models arise naturally in the XP formalism, and the existence of such codes in the XS stabiliser formalism had already been established in Ref. [18]. Such models may be useful in achieving fault-tolerant quantum computation [16] as well as understanding physical phenomena such as the fractional Quantum Hall Effect [24]. In Ref. [10], the authors showed that all twisted quantum doubles (TQDs) with Abelian anyons can be represented as qudit stabiliser codes. It would be interesting to see if there is a similar result for non-Abelian TQDs represented as XP codes. You can explore the logical operator structure of various topological codes, including Twisted Quantum Doubles, in the linked Jupyter notebook.
One of the most exciting implications of this work is that no-go theorems which apply to Pauli stabiliser codes and commuting stabiliser codes do not necessarily apply to XP codes. Such results exist, for instance, in the area of self-correcting quantum memories (Ref. [4] on page 23). Rather than rely on active error correction, a self-correcting quantum memory is a system where large scale errors would be suppressed by a macroscopic energy barrier. As XP codes involve stabilisers which are not Paulis and which may not commute, they are worth investigating for potential use as self-correcting memories.

A Linear Algebra over Rings
Most readers will be familiar with linear algebra techniques for vector spaces over a field -for instance, solving linear equations or finding a basis of a subspace. In this paper, we work with vectors over Z N , which is a ring in general rather than a field. Linear algebra over rings is not covered in standard linear algebra textbooks, so we give an introduction here (for more background, see Refs. [25] and [5]).
We start with basic concepts from ring theory in Section A.1. We then consider the row span of a matrix over a ring. For vector spaces, we can calculate the Reduced Row Echelon Form (RREF) of a matrix and this gives us a basis for the subspace spanned by the rows of the matrix. In Section A.2, we introduce the Howell matrix form which is a generalisation of the RREF for rings. Calculation of the Howell basis is central to many of the algorithms in this paper.
We show how to solve linear equations modulo N in Section A.3 and how to find the intersection of spans in Section A.4. These techniques are used when calculating the logical operators of XP codes.

A.1 Ring Concepts
A ring R is a set of elements with addition and multiplication binary operations. Elements of a ring are not guaranteed to have multiplicative inverses. Elements which do have inverses are called units. In contrast, a zero divisor is an element a = 0 where ab = 0 for some b = 0.
We define an equivalence relation such that a ∼ b ⇐⇒ a = ub for some unit u (or a is an associate of b ). For each element a of Z N , we can calculate a minimal associate m a := GCD (N, a).
Notice that m a = 1 if and only if a is a unit.

A.2 Spans of Matrices and the Howell Matrix Form
We can define the span of a matrix B ∈ R m×n with rows b i over a ring R as: Spans over rings can be considered subgroups of R n under component-wise addition over R (i.e. Span R (B) = B (R,+) ≤ R n = I (R,+) ).
Where R is a field (e.g. R = Z q where q is prime), the RREF gives us a basis of the span and two matrices have the same span if and only if they have the same RREF. The Howell form plays an analogous role for spans over rings.
The Howell matrix form or Howell basis of B ∈ R m×n over a ring R, denoted How R (B), is an n × n matrix of form: The entries of How R (B) are subject to the following constraints: • Diagonal entries (marked a, b, c above) are minimal associates in Z N .
• If the diagonal entry is zero, the whole row is zero • Entries below the diagonal entries are zero • Entries above the diagonal entries are strictly less than the diagonal entry (marked · above), unless the diagonal entry is 0 in which case they are unrestricted (marked * above).
The Howell matrix is the unique matrix of the above form which has the Howell property. Let Where R is a field, How R (B) = RREF R (B). In the special case of binary matrices (i.e. where R = Z 2 ), the RREF has a particular form. In particular, for any leading index l the entries in column l are strictly less than 1 and hence are zero. This fact is useful when determining the special form of orbit representatives (see Section 4.3.2).

A.3 Solving Linear Equations over Rings
In this section, we show how to solve linear equations over rings using the Howell matrix form. Given the matrix A ∈ R m×n and a constant vector c ∈ R m , we wish to solve for the vector x ∈ R n in the linear equation: We calculate the Howell form of the transpose A T so that: where T ∈ R m×m and S ∈ R m×n . As part of this calculation, we also obtain the Howell basis K for Ker R (A) such that KA T = 0. We can solve Eq. (137) if c ∈ Span R (T ) so that for some vector v ∈ R 1×m : In this case, the solutions for x are given by: where a ranges over all values of R n . That x is a solution to Eq. (137) can easily be verified by substitution. We can also write the solution set as an affine span x ∈ −vS + Span R (K) (see Eq. (141) below).

A.4 Intersections of Spans and Affine Spans
When calculating the codewords (Chapter 4) and logical operators (Chapter 6) of an XP code, we work with affine spans which can be identified with cosets of row spans. To find the logical X operators, we need to determine the intersection of affine spans (see Section E.2.3). In this section, we explain how to compute the intersection of two affine spans and introduce the residue function which identifies which coset a vector belongs to.

A.4.1 Affine Span Definition
Given an offset a ∈ R n and a matrix B ∈ R r×n , the affine span is defined as: Because Span R (B) is a subgroup of R n , we can also consider affine spans to be cosets (i.e. a + Span R (B) = a + B (R,+) ). The residue function identifies the coset of a vector and can be used to determine if two vectors are in the same affine span. The residue function is defined as: Res R (B, a), where:  R (B, b).

A.4.2 Algorithm for Intersection of Spans
Given two matrices A ∈ R r×n and B ∈ R s×n , we can find the intersection of the respective spans (Span R (A) ∩ Span R (B)) as follows: 1. Form the (r + s) × n matrix C = A B

A.4.3 Algorithm for Intersection of Affine Spans
The intersection of two affine spans is either empty or an affine span. Assume we are given two affine spans a + Span R (A) and b + Span R (B). There exists a vector c in the intersection if and only if we can find vectors u ∈ R r and v ∈ R s such that: This is possible only when a − b ∈ Span R (A) ∪ Span R (B) which is true if and only if: In this case, we set c = (b + Res R (A, a − b) and the intersection is given by:

B Canonical Generator Algorithm -Proof of Result
In this appendix, we provide a proof of Proposition 4.1. This is an important result which states that we can calculate a set of canonical generators of unique form for any XP group. This allows us to determine whether two sets of XP operators generate the same group and also identify a set of generators for the diagonal subgroup. The proof of the proposition is constructive and relies on the following algorithm:

Canonical Generator Algorithm
The algorithm for producing the canonical generators from an arbitrary set of XP operators G is: 1. Simplify X Components: let G X be the binary matrix whose rows are the X components of the operators in G. We can put G X into RREF by using row operations over Z 2 . These row operations correspond to group operations between elements of G and we update G accordingly.
2. Split G into diagonal and non-diagonal operators: let S X be the non-diagonal operators and S Z be the diagonal operators.
3. Add squares and commutators of S X : squares and commutators of operators in S X are diagonal -add these to S Z .

4.
Add commutators between S Z and S X : add to S Z all possible commutators between elements of S Z and elements of S X . Where N = 2 t is a power of 2, we do this step t − 1 times. 6. Simplify Z Components of S X :

Simplify
We restate Proposition 4.1 here for clarity: 1. Let S X be the binary matrix formed from the X-components of the S X . S X is in Reduced Row Echelon Form (RREF).
2. Let S Zp be matrix whose rows are the image of S Z under the Zp map of Section 3.4 (i.e. Zp(XP N (p|0|z)) = (2z|p)). The matrix S Zp is in Howell Matrix Form (see Appendix A).

For XP
The following properties hold for the canonical generators: Property 1: All group elements G ∈ G can be expressed in the generator product form of Eq.
Property 2: Two sets of XP operators of precision N generate the same group if and only if they have the same canonical generators.
Proof. Steps 1-2 of the algorithm create a list of non-diagonal operators S X whose X-components are in RREF, plus diagonal operators S Z . We claim that after these operations, S X , S Z = G . Over Z 2 , the row operations to convert the matrix G X into RREF involve either: The row operations can be translated into group operations on G as follows: 1. Swapping the order of generators; or 2. Replacing a generator by a product of generators i.e.
For case 2, we need to check if G i is still in the group after the row operations. Because G j is unchanged, G −1 j remains in the group so we have Steps 3-4 of the algorithm ensure that all possible squares and commutators of the generators are added to the list of diagonal operators S Z . Now we show that where N = 2 t , that t − 1 rounds of adding commutators is sufficient. When we calculate the commutator of operators A 1 , A 2 , the resulting degree (see Section 3.5) is at most half the degrees of A 1 , A 2 : recall the COMM rule of Section 3.3: As X 2 = P N = I, the maximum degree of a precision N operator is N = 2 t . Hence, after t − 1 rounds of taking commutators, a further round of commutators yields operators of degree 1 (i.e. phase multiples of I). Note that all of the operators added to S Z are in G so there is no change to S X , S Z in this step.
Step 5 ensures that S Zp , the matrix formed from the phase and Z-components of S Z under the Zp map is in Howell matrix form. In Section 3.4, we showed that the Zp map is a group homomorphism so group generators in Z n+1 2N , i.e. the rows of the Howell matrix, correspond to diagonal group generators in X P N,n , i.e. S Z so there is no change to the group generated by S Z in this step.
In Step 6, the residue function of Eq. (142) ensures that the Z-components of the non-diagonal canonical generators are of the correct form. The adjustment corresponds to multiplication of elements in S Z so we are assured that the final set of generators meets the invariant G = S X , S Z .
To prove Property 1, we need to show that any element G ∈ G can be expressed n the generator product form of Eq. (25) G = S a X S b Z . We have already shown that G = S X , S Z . Hence, we can write G as a string of operators from S X , S Z . Now assume we have a diagonal operator B ∈ S Z which occurs immediately before a non-diagonal operator A ∈ S X . We can write: The commutator B −1 A −1 BA ∈ S Z , so we can always move diagonal operators to the right of non-diagonal operators. Now assume we have two non-diagonal operators A j , A i ∈ S X which occur immediately next to each other in the string, but out of order (i.e. i < j). We can move A j to the right of A i by using commutators as follows: The commutator (A −1 j A −1 i A j A i ) ∈ S Z , so we can ensure A i , A j occur in the correct order with a diagonal operator to the right.
Reordering the non-diagonal operators may result in squares or higher powers of non-diagonal operators arising in the string. As A 2 ∈ S Z for any A ∈ S X , any power of A can be written as A q = AB for q odd or A q = B for some B ∈ S Z . Hence, G can be written with powers of A in Z 2 . Accordingly, any G ∈ G can be written as a string of the form in Property 1.
To establish Property 2, note that the Howell matrix form and RREF are unique. Thus, for any operators which generate the same group, the canonical form will be the same.

C Coset and Orbit Structure of Codewords
In Chapter 4, we gave an algorithm for generating the codewords by applying the orbit operator to the orbit representatives. In this appendix, we provide proofs underlying the algorithm. The results in this appendix assume we have the canonical generators S X and S Z (see Section 4.1) and the set of binary vectors E, which is the Z-support of the simultaneous +1 eigenspace of S Z (see Section 4.2.2). Our aim is to calculate a basis of the codespace stabilised by S X , S Z .
In Proposition C.1, we show that the image under the orbit operator of any |e where e ∈ E is stabilised by S X , S Z . Let S X be the binary matrix formed from the X-components of the S X and E m = {Res Z2 (S X , e) : e ∈ E} be the orbit representatives. In Proposition C.2, we show that E is closed under addition by elements of the span S X . In Proposition C.3, we show that the cosets m i + S X , m i ∈ E m partition E. In Proposition C.4, we show that the image of E m under the orbit operator forms a basis of the codespace. Finally, we show that the orbit representatives have a unique form, which is used in the graph search algorithm of Section 4.3.2.

Proposition C.1 (Codewords as Orbits)
Given canonical generators for a code S X and S Z , let E = {e : e ∈ Z n 2 , B|e = |e , ∀B ∈ S Z } be the Z-support of the simultaneous +1 eigenspace of S Z .
Then O S X |e is stabilised by all elements of S X , S Z , for any |e ∈ E.
Proof. It is sufficient to prove this for the generators A i ∈ S X and B j ∈ S Z . Let B j ∈ S Z be a diagonal generator. Then we have: Let A i ∈ S X be a non-diagonal operator.
We can move A i to the right by applying commutators. We can then move the commutators to the right. Let i be the length r binary vector which is all zero, apart from component i which is 1 and let v = v ⊕ i. As all commutators are diagonal and so are in S Z , we can write: Proposition C.2 (E closed under addition by S X ) If e ∈ E, then e ⊕ x ∈ E for all x ∈ S X .
Proof. Let x := uS X mod 2 ∈ S X and C := S u X . Then C|e = ω p |e ⊕ x for some p ∈ Z 2N . Let B ∈ S Z and D = B −1 C −1 BC ∈ S Z . Then because B, D ∈ S Z , BD|e = |e and so: Hence, C|e = ω p |e ⊕ x is in the simultaneous +1 eigenspace of the S Z and so e ⊕ x ∈ E.

Proposition C.3 (Cosets of E m partition E)
The cosets m i + S X partition E i.e.: But by the definition of orbit representatives for any e ∈ E we can calculate Res Z2 (S X , e) ∈ E m hence e ∈ m i + S X for some m i ∈ E m . The fact that cosets of a subgroup partition the group is a well-known result from group theory. Hence if (m i + S X ) ∩ (m j + S X ) = ∅ then m i ∈ m j + S X . But then because the RREF is unique m i = Res(S X , m i ) = m j so i = j.
Proposition C.4 (The |κ i are a basis of C) The |κ i are a basis of the codespace C stabilised by the canonical generators S X , S Z .
Proof. First, we show that the |κ i are independent. The Z-support of the codeword |κ i is the coset ZSupp(|κ i ) = m i + S X and so by Proposition C.3 the Z-support of the codewords partition E. Hence |κ i are independent.
Next, we show that the |κ i span the codespace C. Let |ψ ∈ C. Then |ψ is stabilised by all elements B ∈ S Z . Let e ∈ ZSupp(|ψ ) then because B is diagonal, B|e = ω p |e , ∃p ∈ Z 2N and this implies B|e = |e , ∀e ∈ ZSupp(|ψ ). Hence ZSupp(|ψ ) ⊂ E. Now let λ i be the coefficients of |m i in |ψ so that: For e ∈ ZSupp(|ψ ), we now show that the coefficient e|ψ is determined by the λ i . Because e ∈ E, there exists unique i, u ∈ Z r 2 such that e = (m i + uS X ). The operator S u X ∈ S X and so S u X |ψ = |ψ . The action of S u X on |m i is given by S u X |m i = ω p |e , ∃p ∈ Z 2N . Hence the coefficient of |e in |ψ is given by e|ψ = λ i ω p = λ i e|κ i . Hence: Hence any |ψ ∈ C can be written as a linear combination of the |κ i and the result follows.
The orbit representatives have a form which is unique for each coset, which proves useful in the graph search algorithm of Section 4.3.2.

D Proof of Results: Classification of XP Stabiliser States
In this appendix, we provide detailed proofs of the results in Chapter 5. In Section D.1, we set out some basic results which are useful for working with integer and binary vectors. In Section D.2, we prove Proposition 5.1 regarding the form of the phase function of an XP stabiliser state. Finally in Section D.3, prove that the algorithm for representing weighted hypergraph states as XP stabiliser states gives the correct result.

D.1 Operations on Binary and Integer Vectors
The results in Chapter 5 involve operations on binary and integer vectors. This section sets out some basic results for these types of vectors. We use component wise addition and multiplication of vectors and a dot product of vectors over the integers. Given two vectors a, b ∈ Z n the dot product is defined as: Hence, the dot product is the sum of the entries of the component wise product of two vectors. Accordingly, we can write the following rule for dot product over the component wise product: We also have a distributive rule for dot product over component wise addition: The usual rule for scalar products also applies -for u ∈ Z: The weight of a binary vector can also be thought of as a dot product.
The support of the addition of binary vectors modulo 2 is the symmetric difference of the supports: We often apply the following identity for binary vectors: where operations on the RHS are over the integers. This generalises to the following identity for binary vectors x j , j ∈ [0 . . . r − 1] of length n:

D.2 Phase Functions of XP Stabiliser States
In this section, we prove Proposition 5.1 which classifies the form of the phase functions of XP stabiliser states.
(b) For N = 2 t , the maximum degree of the phase function is t + 1.
Proof. Let S X = {XP N (p i |x i |z i )} and let s i := i<j<r u j x j . Using Eq. (170) and the dot product results of Section D.1, the phase component of S u X |m can be written as follows: The first term in the above equation is linear in u i and setting s := c ∪ {i}, the second term is also of the required form so part (a) follows. Now let N be a power of 2 such that N = 2 t . As ω 2N = ω 2 t+1 = 1, any terms in the phase function with degree d − 1 ≥ t + 1 or d > t + 1 have coefficients which are multiples of 2N and hence generate trivial phases. Hence, the maximum degree of the phase function is t + 1 and part (b) follows.

D.3 Representing Weighted Hypergraph States as XP Stabiliser States
In this section, we show that the algorithm of Section 5.4 for representing weighted hypergraph states as XP stabiliser states produces the required results. The embedding operator of Eq. (57) is defined in terms of M r m , which is the binary matrix whose columns are the bit strings of length r of weight between 1 and m inclusive. This construction is similar to that used in classical simplex codes and Reed-Muller codes [3].
In the following proposition, we break M r r into blocks W r k where the columns all have weight k and calculate the weight of the product of t rows of W r k .

Proposition D.1 (Weight of Vector Products)
Let W r k be a matrix whose columns are the bit strings of length r with weight k. Let p t = 0≤i<t x i be the product of the first t rows of W r k where t ≤ r. Then: Proof. We can think of wt( 0≤i<t x i ) as the number of columns u of W r k such that 0≤i<t u[i] = 1. If t > k then 0≤i<t u[i] = 0 for all columns because wt(u) = k < t and the product includes at least one zero.
If t ≤ k then the first t entries in u must all be one, implying that the last r − t entries of u must include k − t values of 1. There are r−t k−t ways of constructing bit strings of weight k which have the first t entries equal to 1.
We now consider dot products with the alternating vector a of Eq. (58) which is 1 when the weight of the corresponding column of M r r is even and −1 when the weight is odd. The vector a will be used to construct the Z-component of the non-diagonal stabilisers of the XP code.
We now show that the alternating vector a allows us to construct an XP stabiliser state which has a phase function corresponding to a generalised controlled phase operator.  Table 4, the group commutator of A i and A j is: (b) Applying Eq. (176) and noting that the phase components of the A i are all trivial, the phase component of S u X |0 is: Applying Proposition D.2, a · ( j∈s x j ) = 0 if |s| < r and (−1) r otherwise. Hence, p = 2 r−1 0≤j<r u j as required. We now show how to optimise the embedding operator to reduce the number of qubits required to represent the action of generalised controlled phase operators CP (p/q, v) where p/q = 1/2: We now show that D(2a(x j − x i )) fixes all elements of the Z-support of |ψ . Let e u := uS X + m ∈ ZSupp(|ψ ). Then using the notation of Proposition 5.1 and Eq. (170), the phase applied by D N (2a(x j − x i )) to |e u can be written By Proposition D.2, if r > 1 then a·x j = a·x j = 0. Similarly, if |s∪{i}| < r then a·x i k∈s x k = 0. If |s ∪ {i}| = r, then a factor of 2 r = 0 mod 2N always occurs -hence the operator applies a trivial phase and part (a) follows. Due to Proposition D.2, we can multiply the generators A i by powers of C without changing the phase function of the state |ψ , so part (b) follows.
We now show how to apply Proposition D.4 to reduce the number of qubits required to represent |φ = CP (1/2, 1)|+ ⊗r as an XP stabiliser state. We set N = 2 r−1 and let x i be the ith row of M r r . We define the non-diagonal stabiliser generators ) -these are the same operators as in Proposition D.4. The phase function of |ψ = O S X |0 is f (u 0 , . . . , u r−1 ) = 2 r−1 0≤i<r u i . This imparts a phase of −1 = ω N when u = 1. Define the S Z as in Eq. (62). By part (a) of Proposition D.4, the elements of S X commute up to a diagonal operator which fixes elements of the Z-support of |ψ hence S X , S Z stabilises |ψ .
To extend this method to generalised controlled Z operators of form CP (1/2, v), we need to ensure that uv = v for any other operator CP (p/q, u) involved in the weighted hypergraph state. Otherwise, we cannot guarantee that the commutators of the operators in S X act trivially on the Z-support of the embedded state.

E Logical Operators -Proof of Results
In this appendix, we provide proofs for the main results in Chapter 6. We first prove two results about the properties of logical XP operators. We next show that the algorithms of Sections 6.2 and 6.3 produce valid logical operators, and that they produce all possible operators of XP form. We then show how to find valid phase and Z components for logical X operators. We then prove the observations of Example 6.4 regarding Reed-Muller codes. Finally, we prove that the more efficient algorithms of Section 6.6 work correctly.

E.1 Properties of Logical XP Operators
In this section, we prove two results on the properties of logical XP operators. Given the codewords |κ i of Section 4.4, the first result states that an XP operator is a logical operator if and only if its action on the codewords can be described in terms of: • A permutation of the codewords; and • A phase applied to each codeword This result is used to prove that the logical operator and logical identity algorithms work correctly.
The second result states that an XP operator is a logical operator if and only if its commutators with logical identities are logical identities. It is an efficient way in practice to verify if an XP operator is a logical operator on the codespace.

Proposition E.1 (Action of Logical Operators)
An XP operator A is a logical operator if and only if its action can be described by a permutation π of the codewords such that π 2 = 1 and a vector f ∈ Z dim(C) 2N specifying the phase applied to each codeword.
Proof. Let A = XP N (p|x|z) be an XP operator. Applying the rule in Eq. (20), A acts on computational basis elements as follows: Hence, the image of a computational basis element under an XP operator cannot be a superposition of computational basis elements. Now consider how A acts on the codewords {|κ i } of Section 4.4. Let E i be the Z-support of the codeword |κ i and let r be the number of non-diagonal canonical generators (i.e. r = |S X |). Then |E i | = 2 r and E i ∩ E j = ∅ for i = j. Hence, the image of a codeword under an XP operator cannot be a superposition of codewords.
Now assume A is a logical operator and so preserves the codespace C. As A|κ i ∈ C for each codeword and A cannot create superpositions of codewords, then A|κ i = ω qi |κ j for some codeword |κ j and q i ∈ Z 2N . Because the image of the codewords under A must span the codespace, A must permute the codewords. The square of any XP operator is diagonal (see Section 3.3) so the square of the permutation must be 1 and the action of A is as claimed.
In the PSF, any logical operator L on the codespace must commute with the stabiliser generators. In the XPF, we instead work with the generators M of the logical identity group. The group commutator of a logical operator L with each element of M must be in the diagonal subgroup M Z . In practice, this gives an efficient test for determining if a given operator is a logical operator on the codespace.

Proposition E.2 (Commutators Logical Operators and Logical Identities)
Let M be the logical identity generators as in Section 6.2. L is a logical XP operator if and only Proof. Assume A ∈ M, L is a logical XP operator and {|κ i } are the codewords of Section 4.4. By Proposition E.1, there exists a phase vector f and a permutation π such that for all i: From Section 3.3, we know that group commutators are always diagonal operators, hence Conversely, assume that A −1 L −1 AL ∈ M Z , ∀A ∈ M. This is also true for any A ∈ M . Then for each codeword |κ i : Hence L|κ i is in the codespace for all |κ i . Because L is an XP operator L|κ i cannot be a superposition of codewords and so L|κ i = ω pi |κ j for some p i ∈ Z 2N and |κ j . Because L 2 is diagonal the map π : i → j squares to 1 and hence is a permutation. Therefore we can describe the action of L as L|κ i = ω pi |κ π(i) and so L is a logical XP operator by Proposition E.1.

E.2 Logical Identity and Logical Operator Algorithms
In this section, we prove that the logical identity algorithm of Section 6.2 and the logical operator algorithm of Section 6.3 yield generating sets of operators. We first consider the algorithms for diagonal operators, then those for non-diagonal operators. We then show how to find logical X operators by using the intersection of affine spans algorithm of Section A.4.

E.2.1 Diagonal Operator Algorithms
In this section, we show that the algorithms of Sections 6.3.1 and 6.2.1 produce sets of diagonal logical generators and diagonal logical identity generators respectively. Assume we have the codewords in the orbit form of Eq. (35) -i.e. |κ i = 0≤j<2 r ω pij |e ij . Let E be the Z-support of the codewords (see Section 4.2.2). We first look at diagonal logical identity operators and prove the following proposition:

Proposition E.3 (Diagonal Logical Identity Group)
The algorithm in Section 6.2.1 produces a list of diagonal XP operators M Z which generate the diagonal logical identity XP operators for the codespace.
Proof. The binary matrix E M is the matrix formed by taking (e|1) as rows, where e ∈ E. If (z k |p k ) is a row of the Howell basis K M of Ker(E M ), then (z k |p k ) · (e ij |1) mod N = 0. Let A k := XP N (2p k |0|z k ) then A k |e = ω 2p k +2e·z k |e = ω 2(z k |p k )·(e|1) |e = |e . Hence, A k applies a trivial phase on each element of E and hence on each codeword. Because Ker Z N (E M ) = Span Z N (K M ), the A k generate all diagonal logical identity operators and so M Z := {A k }.
We next look at the diagonal logical operators and show the following:

Proposition E.4 (Diagonal Logical Operators)
The algorithm in Section 6.3.1 produces a list of diagonal XP operators L Z which together with ωI and M Z generate the diagonal logical XP operators for the codespace.
Proof. We define the binary matrix E L used in the logical operator algorithm as follows. For each e ij in Eq. (35), let i be a binary vector of length dim(C) which is all zeros apart from the ith component which is 1. The vector i is a "codeword index" that tells us which codeword the row belongs to. Let E L be the matrix formed by taking (e ij |i) as rows. Let K L be the Howell basis of Ker Z N (E L ) and let (z k |p k ) be a row of K L . Then for all values of i and j, (z k |p k )·(e ij |i) mod N = 0 and so z k · e ij mod N = −p k [i] mod N . Now consider how the diagonal XP operator B k := XP N (0|0|z k ) acts on the Z-support of the codewords: In other words, the action of B k is constant on the Z-support of each codeword and so is a logical operator with phase vector f k = −2p k . The B k , together with the operator ωI, generate all possible diagonal logical operators because Ker Z N (E L ) = Span Z N (K L ). We now show how to find non-trivial diagonal operators L Z which together with ωI and M Z generate the same group as the B Z := {B k } and ωI, reflecting steps 4 and 5 of the algorithm in Section 6.3.1. Because we include ωI as a generator, we can just consider the space spanned by the Z components of the operators over Z N . Let M Z and B Z be the matrices whose rows are the Z-components of the M Z and B Z respectively. For each row z k of B Z we let r k = Res Z N (M Z ) so that z k = (r k + uM Z ) mod N for some vector u ∈ Z

E.2.2 Non-diagonal Operator Algorithms
In this section, we show that the algorithms for non-diagonal operators yield valid logical operators and logical identities respectively. We then show that the operators produced are generating sets for the respective groups. Assume we have the coset decomposition of the Z-support of the codewords as in Eq. (89) i.e. E = E q + S X + L X . Recall that the rows of S X are the X-components of the non-diagonal canonical generators and that the binary vector x ∈ L X if and only if E m ⊕ x = E m (see Section 6.3.2).

Proposition E.5 (Non-diagonal Logical Operators)
Given a binary vector x ∈ L X , the algorithm in Section 6.3.2 yields a non-diagonal logical operator with X-component equal to x or FALSE if no such operator exists.
Proof. Given x ∈ L X and applying Proposition E.1, we wish to find A = XP N (0|x|z) for which A|κ i = ω f [i] |κ π(i) for some phase vector f and some permutation π.
Because x ∈ L X , we know that m i ⊕ x = m j for orbit representatives m i , m j . Define π : i → j if m i ⊕ x = m j . Then π is a map which squares to 1 and so is a permutation. Now assume we have the codewords in the orbit format of Eq. (35). Let e ij = e ij ⊕x and let p ij be the phase of e ij in the codewords. We require that Aω pij |e ij = ω f [i]+p ij |e ij , ∀i, j. Calculating the action of A on ω pij |e ij : The phase of |e ij is ω f [i]+p ij when: As the phase f [i] is fixed for each codeword |κ i , for there to be a valid solution p ij − p ij to be either even or odd for all j. Let a i = (p ij − p ij ) mod 2 and p ij = (p ij − p ij − a i )/2. Define the vector q := (a i − f )/2. Hence: Letting p be the vector corresponding to the p ij , we can write this in matrix form: Solutions to this equation are members of the affine span (see Eq. (141)): where K L is the Howell basis of Ker Z N (E L ) and b ∈ Z n N × Z dim(C) N is a constant. We can either find b or show that no solution exists by using linear algebra modulo N (see Section A.3). If no such solution exists, return FALSE. Otherwise, the operator A = XP N (0|x|z) is the required non-diagonal logical operator.
The algorithm for non-diagonal logical identity operators can be considered a special case of the algorithm for non-diagonal logical operators, with the matrix E M substituted for E L and the proof is omitted.
Corollary E.6 (Non-diagonal Logical Identity Group) Given codewords |κ i in orbit format and x ∈ S X , the algorithm in Section 6.2.2 yields a nondiagonal operator A with X-component x such that A|κ i = |κ i , ∀i, or returns FALSE if no such operator exists.
We next show that the operators produced by the algorithms give us a generating set. We first show that the logical identity group is generated by the operators yielded by the logical identity algorithm.

Proposition E.7 (Logical Identity Group is Generated by M)
The logical identity group for an XP code is the group generated by M as calculated in Section 6.2: Proof. If A ∈ M then A|κ i = |κ i for all codewords |κ i by construction so A ∈ I XP , and so I XP ⊃ M . We now prove the converse. In Proposition E.3, we showed that M Z generates the diagonal subgroup of I XP Let B = XP N (p|x|z) be a non-diagonal operator in I XP . Then x ∈ Span Z2 (S X ) as defined above. Hence, we can find a binary vector v such that x = vS X mod 2. Finally, we show that the logical operators with X-components in L X , along with the stabiliser generators and the diagonal logical operators generate the entire logical operator group.

Proposition E.8
Let E be the Z-support of the codewords of an XP code and let E = E q + S X + L X be the coset decomposition of E as in Eq. (89). Let M be the logical identity group as in Section 6.2, let L Z be the set of diagonal operators as in Section 6.3.1 and let L X be a set of logical operators with X-components drawn from the rows of L X . Then the logical operator group is given by: Proof. Say we have a logical operator with a non-trivial X-component of the form A = XP N (p|x|z). The action of A on |e for e ∈ E is A|e = ω p+2e·z |e ⊕ x . We have shown that the codespace is spanned by the |κ i which have Z-support exactly equal to E. Because logical operators preserve the codespace, X-components of logical operators must satisfy the constraint: All possible X-components for logical operators are given by S X + L X . To see this, assume there exists some x / ∈ S X + L X meets the constraint in Eq. (204). Then Res Z2 (S X , x) / ∈ L X meets the constraint in Eq. (204), which is a contradiction.
Next, we show that any logical operator can be written as A = XP N (p|x|z) = LS where L has X-component in L X and S ∈ M X . We know that x ∈ S X + L X so x = (uS X + vL X ) mod 2 for some binary vectors u, v. Let S = M u X then L = AS −1 is a logical operator with X component in L X . Now assume that there are two different logical operators with X-component x ∈ L X -say A 1 and A 2 . The product B = A 1 A −1 2 is a diagonal logical operator so A 1 is the same as A 2 up to a product of a diagonal logical operator. Applying Proposition E.4, B ∈ ωI, M Z , L Z Accordingly, we can generate all possible logical operators by finding the non-diagonal logical operators with X-components in L X . Together with the logical identity generators M, ωI and L Z , these generate the full set of logical operators.

E.2.3 Diagonal Component of Logical X Operators
We have demonstrated how to find a non-diagonal logical operator with X-component in L X . This will not necessarily act as a logical X operator. In particular, a logical X should square to a logical identity and in this section, we show how to ensure that this is the case.
Assume we have used the algorithm in Section 6.3.2 to find a logical operator B = XP N (0|x|b). Our aim is to calculate a logical X operator A = XP N (p|x|z) such that A 2 is a logical identity. As A 2 is diagonal, we require A 2 ∈ M Z . Our strategy is to first find the Z component of A, then adjust the phase component.
We first look at which Z components are possible for logical operators with the same X component as B. We can multiply B by any diagonal logical operator in M Z , L Z and get a logical operator, and all possible Z components of such operators arise in this way. Let M Z , L Z be the matrices formed from the Z components of M Z , L Z respectively. Writing C = Span Z N (C), the possible Z components are given by the affine span: We next address the condition that the Z component of A 2 , which we denote z 2 here, has to be in M Z . By applying the square rule of Section 3.3: We can add any element of diag(x) to z and still ensure z 2 ∈ M Z because where x[i] = 1, z 2 [i] is guaranteed to be zero. Hence z 2 ∈ M Z when z ∈ Sp a defined as: Hence, z ∈ Sp a ∩ Sp b . If this span is not empty then we can find z such that z 2 = uM Z mod N ∈ M Z for some vector u. Let p z , p u be the phase components of XP N (0|x|z) 2 and M u Z respectively. We set the phase component of A to be p = (p u − p z )/2.

E.3 Reed-Muller Codes
Reed-Muller codes are well-known Pauli Stabiliser codes. We can also look at them as XP codes and better understand their logical operator structure. In the Proposition below, we show that they are self-dual codes and have transversal logical operators at precision N > 2. To demonstrate the results, we apply the techniques of Appendix D.

Proposition E.9 (Reed-Muller XP Codes)
The Reed-Muller code on 2 r − 1 qubits can be written as the codespace of a precision N = 2 r−2 code whose stabiliser generators are symmetric in X and P. The code has a transversal logical diag(1, exp(−2πi/2 r−1 )) operator. We claim that the codespace of S X , S Z is spanned by {|0 L , |1 L }. For this, we need to show that the simultaneous +1 eigenspace of the S Z is given by {|e } where e ∈ Span Z2 {1, x i : 0 ≤ i < r}. Let u ⊂ [0 . . . r − 1] and let s u := j∈u x j . Note that XP N (0|0|x k )|s u = ω 2x k ·su |s u . Hence we need to show that x k · s u mod 2 r−2 = x k · (1 ⊕ s u ) mod 2 r−2 = 0.
Applying Proposition D.1 the weight of the product of t distinct x i is 2 r−t because: By setting t = 1 in Eq. (208) we see that x k · 1 = 2 r−1 . Hence: x k · (1 ⊕ s u ) = x k · (1 − s u ) = x k · 1 − x k · s u = 0 mod 2 r−2

E.4 Modified Algorithms for Logical Identity Group and Logical Operators
Our objective here is to show that where N = 2 t , we can calculate the logical identity group and logical operators without first calculating the codewords in full. Assume that the codewords in orbit form are as in Eq. (35) and let E be the Z-support of the codewords.
We can disregard any multiples of N = 2 t so we can write: By Lemma E.11 and Corollary E.12, we know that all elements on the RHS are in Span Z N (E t ) hence e ∈ Span Z N (E t ), ∀e ∈ E. Hence, all linear combinations of elements of E are also in the span and the result follows.
The main results of the section now follow by application of the previous proposition: Proposition E.14 (Modified Logical Identity Algorithm) Let E M be as defined in the algorithm of Section 6.2.1 i.e. the rows of E M are the binary vectors e ∈ E, plus a final column of all 1's. Let N = 2 t and E t be the elements of E of orbit distance at most t from the core E q . Let E M be the matrix formed from the rows of E t plus a row of 1's. Then: Proof. Let E = E q + S X + L X be the coset decomposition of E. Let E q be the vectors in E q with an appended 1 (i.e. E q = {(q|1) : q ∈ E q . Let G X = RREF(L X ∪ S X ) and let L be G X with an appended 0 so L = {(x|0) : x ∈ G X }. Then E M = E q + L . The result follows by applying Proposition E.13.

Proposition E.15 (Modified Logical Operator Algorithm)
Let E L be as defined as in the algorithm of Section 6.3.1 i.e. the rows of E L are the binary vectors e ∈ E, plus a codeword index i which identifies which codeword the row belongs to. Let N = 2 t and E t be the elements of E of orbit distance at most t from the orbit representatives E m . Let E L be the matrix formed from the rows of E t plus the codeword index. Then: Proof. Let E = E m + S X as in Section 4.

F Measurements in the XP Formalism -Proof of Results
In this appendix, we prove the results discussed in Chapter 7. We first prove the results for determining the outcome probabilities for measurement of XP operators. We then explain the stabiliser algorithm for measurement of diagonal Pauli operators of Section 7.3.2.

F.1 Measurement Outcome Probabilities -Proof of Results
In this section, we show how to determine the outcome probabilities for measurement of XP operators assuming we are given the codewords in the orbit form of Eq. (35). We first show how to determine probabilities for measurement of diagonal operators, then look at non-diagonal operators.
Proposition F.1 (Outcome Probabilities -Diagonal XP Operators) Let A be a diagonal XP operator which has +1 as an eigenvalue. Let E be the Z-support of the codewords |κ i . Let E + be the set of binary vectors E + = {e ∈ E : A|e = |e }. Let ρ be an even superposition of the codewords as in Eq. (107) so that ρ = 1 |E| i |κ i κ i |. The probability of obtaining outcome +1 when measuring A on ρ is: Proof. Let the projector onto the +1 eigenspace of A be A + and let |κ + i := A + |κ i . The probability of obtaining outcome +1 is Tr(A + ρA + ) = 1 |E| i κ + i |κ + i . Applying Eq. (22) with λ = +1, the action of the projector A + on a computational basis vectors |e is given by: Let E + i := {e ∈ ZSupp(|κ i ) : A|e = |e }. The action of A + on the codeword |κ i is: The result follows by noting that Pr(+1) = 1 Proof. Let A = XP N (p|x|z) be the operator we wish to measure, and assume we obtain outcome +1. Applying Eq. (23) with λ = +1, the action of A + on a basis vector |e is: Any elements e ∈ ZSupp(|κ i ) where A 2 |e = |e will be eliminated, so let: By calculating Res Z2 (S X , x), we can determine if there exists some B ∈ S X with the same X-component as A. There are two possible cases: for some q ij ∈ Z 2N . Hence: Case 2: B exists: Let B be the element of S X with the same X-component as A and let e ∈ E ± i so that A 2 |e = |e . Let B|e = ω b |e ⊕ x and A|e = ω a |e ⊕ x for some phases a, b ∈ Z 2N . Then e, e ⊕ x ∈ ZSupp(|κ i ) with relative phase ω b . Consider the effect of the projector A + on |e + ω b |e ⊕ x : The result follows by noting that Pr(+1) = 1 |E| i κ + i |κ + i and E ± = i E ± i .

F.2 Analysis of Algorithm for Measuring Diagonal Paulis
In this section, we explain why the algorithm of Section 7.3.2 for measurement of diagonal Pauli operators works. We also consider implications for the complexity of measuring higher precision diagonal operators. Firstly, we show that simulating the measurement of a diagonal Pauli operator reduces to determining the change in the Z-support of the codewords E. Let A = XP 2 (0|0|z) and let |κ i = j ω pij |e ij be the codewords of the code in orbit format of Eq. (35) with Z-support E = {e ij }. Let A + be the projector onto the +1 eigenspace of A. The action of A + on |κ i is given by Eq. (22): Hence, the Z-support of the codewords after measurement outcome +1 is E + = {e ∈ E : A|e = |e }. As A is of precision 2, the action of A on |e is A|e = i 2e·z |e = (−1) e·z |e . Hence E + = {e ∈ E : Par z (e) = 0}. From Proposition F.1, the probability of obtaining outcome +1 is |E + |/|E| and the phase of any |e ij remaining in the codewords is unchanged. Similarly, the Z-support of the codewords after obtaining outcome −1 is E − = E \ E + with probability |E − |/|E|. Therefore, we can simulate measurement by determining E + and E − which in turn requires us to determine Par z (e) for all e ∈ E. Next, we show how the algorithm in Section 7.3.2 correctly determines E + , E − . To calculate E + , we need to determine Par z (e) for all e ∈ E. For any binary vectors x, y, taking parity with respect to z commutes with taking the sum modulo 2. That is: Par z (x ⊕ y) = (x + y − 2xy) · z mod 2 = (x · z + y · z − 2xy · z) mod 2 = Par z (x) ⊕ Par z (y) Looking at Step 1 of the algorithm, assume there exists operators B, C ∈ S X ∪ L X with Xcomponents x, y such that Par z (x) = Par z (y) = 1. Then the X-component of BC is x ⊕ y and from Eq. (255), we know that Par z (x ⊕ y) = 1 ⊕ 1 = 0. Hence, updating S X ∪ L X in Step 1 ensures that Par z (x i ) = 0, for all X-components x i of the updated set S X ∪ L X . We remove B from S X ∪ L X so updating E q by adding vectors of form q l ⊕ x, q l ∈ E q to E q ensures that E = E q + S X + L X is unchanged (S X , L X are the matrices formed from the X-components of S X , L X respectively). Now looking at Step 2 of the algorithm, we can express the binary vectors e ∈ E as linear combinations modulo 2 i.e. e = (q l + uS X + vL X ) mod 2 (see Section 6.4). After Step 1, we have ensured that Par z (x i ) = 0, for all x i ∈ S X ∪ L X . Linear combinations of the x i also have parity 0 and so the parity of e is the same as the parity of q l because: Par z (e) = Par z ((q l + uS X + vL X ) mod 2) = Par z (q l ) ⊕ Par z (uS X ) ⊕ Par z (vL X ) = Par z (q l ) .
So e is in E + if only if Par z (q l ) = 0 which is equivalent to q l ∈ E + q . Let r = |S X |, k = |L X | then E = |E q |2 r+k , E + = |E + q |2 r+k . Hence, the probability of obtaining outcome +1 is Pr(+1) = |E + |/|E| = |E + q |/|E q |. By a similar argument, the result for the outcome −1 is also correct. The underlying reason the algorithm works is that the parity function of Eq. (108) commutes with addition of vectors modulo 2. Hence, the parity of the binary vector e l,u,v ∈ E labelled in accordance with the quantum numbers of 6.4 is the same as the parity of q l ∈ E q (see Eq. (256)). This relationship breaks down for higher precision XP operators (e.g. N = 4).