# Access Functions

## `QuantumBasisElement(F): FldFin -> FldFinElt`

Given a finite field $F = GF(q)$, return the element $\lambda \in GF(q^2)$ in the degree $2$ extension of $F$ which connects the extended and compact formats. For a vector $({\bf a}| {\bf b})$ in extended format over $F$, the corresponding compact vector is ${\bf w}= {\bf a}+ \lambda {\bf b}$.

## `Example: Quantum Basis Element (ex-2560f5)`

The argument to `QuantumBasisElement` is the base field $GF(q)$; the returned element $\lambda$ lies in the quadratic extension $GF(q^2)$.

```magma
> Parent(QuantumBasisElement(GF(2)));
Finite field of size 2^2
> Parent(QuantumBasisElement(GF(3)));
Finite field of size 3^2

```

For $q = 2$ the element $\lambda$ is the generator $w$ of $GF(4)$, and it converts an extended-format vector $(a|b)$ over $GF(2)$ into its compact form $a + \lambda b$ over $GF(4)$.

```magma
> F<w> := GF(4);
> lambda := QuantumBasisElement(GF(2));
> lambda eq w;
true
> a := [GF(2) | 1, 0];
> b := [GF(2) | 0, 1];
> [ a[i] + lambda*b[i] : i in [1..#a] ];
[ 1, w ]

```

## `StabilizerCode(Q): CodeQuantum -> CodeAdd`

## `StabiliserCode(Q): CodeQuantum -> CodeAdd`

```magma
ExtendedFormat: BoolElt                    Default: false
```

The additive stabiliser code $S$ which defines the quantum code $Q$. By default $S$ is returned in the compact format of a length $n$ code over $GF(q^2)$, but if `ExtendedFormat` is set to `true`, then it will be returned in extended format as a length $2n$ code over $GF(q)$.

## `StabilizerMatrix(Q): CodeQuantum -> ModMatFldElt`

## `StabiliserMatrix(Q): CodeQuantum -> ModMatFldElt`

```magma
ExtendedFormat: BoolElt                    Default: false
```

Given a quantum code $Q$ return the additive stabiliser matrix $M$ defining $Q$. By default $M$ is returned in the compact format of a length $n$ code over $GF(q^2)$, but if `ExtendedFormat` is set to `true`, then it will be returned in the extended format as a length $2n$ code over $GF(q)$.

## `NormalizerCode(Q): CodeQuantum -> CodeAdd`

## `NormaliserCode(Q): CodeQuantum -> CodeAdd`

```magma
ExtendedFormat: BoolElt                    Default: false
```

The additive normalizer code $N$ which defines the quantum code $Q$. By default $N$ is returned in the compact format of a length $n$ code over $GF(q^2)$, but if `ExtendedFormat` is set to `true`, then it will be returned in extended format as a length $2n$ code over $GF(q)$.

## `NormalizerMatrix(Q): CodeQuantum -> ModMatFldElt`

## `NormaliserMatrix(Q): CodeQuantum -> ModMatFldElt`

```magma
ExtendedFormat: BoolElt                    Default: false
```

Given a quantum code $Q$ return the additive normalizer matrix $M$ defining $Q$. By default $M$ is returned in the compact format of a length $n$ code over $GF(q^2)$, but if `ExtendedFormat` is set to `true`, then it will be returned in the extended format as a length $2n$ code over $GF(q)$.

## Quantum Error Group

As described in the introduction to this chapter, vectors over a finite field used to describe a quantum stabilizer code actually represent elements of the corresponding quantum error group. For a $p$-ary $N$ qubit system (where $p$ is prime) this error group is the extra-special group with order $2^{2N+1}$ consisting of combinations of $N$ bit-flip errors, $N$ phase flip errors, and an overall phase shift. All groups in this section use a polycyclic group representation.

### `QuantumErrorGroup(p, n): RngIntElt, RngIntElt -> GrpPC`

Return the abelian group representing all possible errors for a length $n$ $p$-ary qubit system, which is an extra-special group of order $p^{2n + 1}$ with $2n+1$ generators. The generators correspond to the qubit-flip operators $X(i)$, the phase-flip operators $Z(i)$, and an overall phase multiplication $W$ by the $p$-th root of unity. The generators appear in the order $X(1),Z(1),\ldots,X(n),Z(n),W$.

### `QuantumBinaryErrorGroup(n): RngIntElt -> GrpPC`

Return the abelian group representing all possible errors on a length $n$ binary qubit system, which is an extra special group of order $2^{2n-1}$.

### `Example: Quantum Error Group (ex-442960)`

The image of a vector in the error group is easily obtained from its extended format representation. We illustrate the connection between symplectic orthogonality as a vector, and commutativity as an element of the error group.

```magma
> n := 5;
> VSn  := VectorSpace(GF(2), n);
> VS2n := VectorSpace(GF(2), 2*n);
> E := QuantumBinaryErrorGroup(n);
> BitFlips   := [E.i : i in [1..2*n] | IsOdd(i)  ];
> PhaseFlips := [E.i : i in [1..2*n] | IsEven(i) ];

```

We first take two vectors which are not orthogonal and show their images in the error group do not commute.

```magma
> v1a := VSn ! [0,1,1,0,1]; v1b := VSn ! [0,1,1,0,1];
> v1  := VS2n ! HorizontalJoin(v1a, v1b);
> v2a := VSn ! [1,0,1,1,0]; v2b := VSn ! [0,1,0,1,1];
> v2  := VS2n ! HorizontalJoin(v2a, v2b);
> SymplecticInnerProduct(v1,v2 : ExtendedFormat := true);
1
>
> e1 := &*[ BitFlips[i]   : i in Support(v1a) ] *
>       &*[ PhaseFlips[i] : i in Support(v1b) ];
> e2 := &*[ BitFlips[i]   : i in Support(v2a) ] *
>       &*[ PhaseFlips[i] : i in Support(v2b) ];
> e1*e2 eq e2*e1;
false

```

Next a pair of orthogonal vectors is shown to commute.

```magma
> v1a := VSn ! [1,1,0,1,0]; v1b := VSn ! [0,0,1,1,0];
> v1  := VS2n ! HorizontalJoin(v1a, v1b);
> v2a := VSn ! [0,1,1,1,0]; v2b := VSn ! [0,1,1,1,0];
> v2  := VS2n ! HorizontalJoin(v2a, v2b);
> SymplecticInnerProduct(v1,v2 : ExtendedFormat := true);
0
>
> e1 := &*[ BitFlips[i]   : i in Support(v1a) ] *
>       &*[ PhaseFlips[i] : i in Support(v1b) ];
> e2 := &*[ BitFlips[i]   : i in Support(v2a) ] *
>       &*[ PhaseFlips[i] : i in Support(v2b) ];
> e1*e2 eq e2*e1;
true

```

### `QuantumErrorGroup(Q): CodeQuantum -> GrpPC`

For a quantum code $Q$ of length $n$, return the group of all errors on $n$ qubits. This is the full error group, the ambient space containing all possible errors.

### `StabilizerGroup(Q): CodeQuantum -> GrpPC`

### `StabiliserGroup(Q): CodeQuantum -> GrpPC`

Return the abelian group of errors that defines the quantum code $Q$, which is a subgroup of the group returned by `QuantumErrorGroup(Q)`.

### `StabilizerGroup(Q, G): CodeQuantum, GrpPC -> GrpPC`

### `StabiliserGroup(Q, G): CodeQuantum, GrpPC -> GrpPC`

Given a quantum code $Q$ with error group $G$ (an extra-special group), return the abelian group of errors of $Q$ as a subgroup of $G$.

### `Example: Quant Stab Group (ex-1844d0)`

The stabilizer group of any quantum stabilizer code over $GF(4)$ will be abelian.

```magma
> F<w> := GF(4);
> Q := RandomQuantumCode(F, 10, 6);
> G := StabilizerGroup(Q);
> IsAbelian(G);
true

```

### `Example: Quant Stab Group Hack (ex-8f08f4)`

In order to make stabilizer groups from distinct codes compatible with one another, the groups must be created within the same super-structure. This is done by first creating a copy of the full error group, and then generating each instance of a stabilizer group as a subgroup.

In this example, the intersection of the stabilizer groups of two random codes is formed. An error group $E$ which will be a common over group for the two stabilizer groups is first created.

```magma
> F<w> := GF(4);
> Q1 := RandomQuantumCode(F, 15, 8);
> Q2 := RandomQuantumCode(F, 15, 8);
>
> E := QuantumErrorGroup(Q1);
> S1 := StabilizerGroup(Q1, E);
> S2 := StabilizerGroup(Q2, E);
> #(S1 meet S2);
2

```
