# Inner Products and Duals

The functions described in this section use the symplectic inner product defined for quantum codes.

## `SymplecticInnerProduct(v1, v2): ModTupFldElt, ModTupFldElt -> FldFinElt`

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

Let $v1$ and $v2$ be two vectors belonging to the vector space $K^{(n)}$, where $K$ is a finite field. This function returns the inner product of $v1$ and $v2$ with respect to the symplectic inner product used for quantum codes. The symplectic inner product in extended format is defined by $(a|b)*(c|d) = ad - bc$, and its definition transfers naturally to the compact format.

Let $p$ be the characteristic of $K$. In extended format the intrinsic returns ${\rm Tr}_{K/GF(p)}(ad - bc)$. In compact format $K = GF(q^2)$ and each coordinate is written as $a + \lambda b$ with $a, b \in GF(q)$ (where $\lambda$ is `QuantumBasisElement`$(GF(q))$); the product $ad - bc$ is formed over $GF(q)$ and the intrinsic returns ${\rm Tr}_{GF(q)/GF(p)}(ad - bc)$, the trace from $GF(q)$ rather than the absolute trace from $GF(q^2)$. In both cases the return value lies in the prime field $GF(p)$ (for example $GF(2)$ when $K = GF(4)$), not in $K$ in general. For binary quantum codes whose compact format is over $GF(4)$ this amounts to `Trace`$(v_1 \cdot \overline{v}_2)$.

This product is an alternating $GF(p)$-bilinear form on $K^{(n)}$ regarded as a vector space over $GF(p)$, but in general it is neither $K$-valued nor $K$-bilinear. To evaluate a $K$-valued alternating form attached to the $K$-space itself, attach the form to the space with `SymplecticSpace` (or `VectorSpace(K,n,J)`) and use `InnerProduct`; see Chapter [Polar Spaces](../../MatricesLinearAlgebra/PolarSpaces/index-polar-spaces.md#chappolarspace).

## `Example: Symplectic Products Compared (ex-176f6b)`

The coding-theory product and an attached alternating form can give different values for vectors with the same coordinates.

```magma
> F<w> := GF(4);
> V := VectorSpace(F,2);
> v := V![1,0];
> x := V![1,w];
> coding := SymplecticInnerProduct(v,x);
> coding;
0
> Parent(coding);
Finite field of size 2
> J := Matrix(F,2,2,[0,1,-1,0]);
> W := SymplecticSpace(J);
> ordinary := InnerProduct(W![1,0],W![1,w]);
> ordinary;
w
> Parent(ordinary);
Finite field of size 2^2

```

## `Example: Symplectic Product Formats (ex-f66c0e)`

Writing each coordinate of the compact vector $[w,0]$ over $GF(4)$ as $a + \lambda b$ with $\lambda = w$ (so $w = 0 + \lambda$ and $0 = 0$) gives the extended vector $[0,0,1,0]$ over $GF(2)$. Both formats yield the same symplectic inner product.

```magma
> F<w> := GF(4);
> V := VectorSpace(F, 2);
> compact := SymplecticInnerProduct(V![w,0], V![1,0]);
> compact;
1
> W := VectorSpace(GF(2), 4);
> extended := SymplecticInnerProduct(W![0,0,1,0], W![1,0,0,0] : ExtendedFormat);
> extended;
1
> compact eq extended;
true

```

## `SymplecticDual(C): CodeAdd -> CodeAdd`

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

The dual of the additive (or possibly linear) code $C$ with respect to the symplectic inner product. By default, $C$ is interpreted as being in the compact format (a length $n$ code over $GF(q^2)$), but if `ExtendedFormat` is set to `true`, then it will be interpreted as being in extended format (a code of length $2n$ over $GF(q)$).

## `IsSymplecticSelfDual(C): CodeAdd -> BoolElt`

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

Return `true` if the code $C$ is equal to its symplectic dual and `false` otherwise. By default, $C$ is interpreted as being in the compact format (a length $n$ code over $GF(q^2)$), but if `ExtendedFormat` is set to `true`, then it will be interpreted as being in extended format (a code of length $2n$ over $GF(q)$).

## `IsSymplecticSelfOrthogonal(C): CodeAdd -> BoolElt`

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

Return `true` if the code $C$ is contained in its symplectic dual. By default, $C$ is interpreted as being in the compact format (a length $n$ code over $GF(q^2)$), but if `ExtendedFormat` is set to `true`, then it will be interpreted as being in extended format (a code of length $2n$ over $GF(q)$).

## `Example: Symplectic Eg (ex-b98847)`

Vectors which are symplectically orthogonal to one another can be used to construct symplectic self-orthogonal codes.

```magma
> F<w> := GF(4);
> V5 := VectorSpace(F, 5);
> v := V5 ! [1,0,w,0,1];
> w := V5 ! [w,1,0,w,w];
> SymplecticInnerProduct(v,w);
0
> C := AdditiveCode<F, GF(2), 5 | v, w>;
> C;
[5, 1 : 2] GF(2)-Additive Code over GF(2^2)
Generator matrix:
[  1   0   w   0   1]
[  w   1   0   w   w]
> D := SymplecticDual(C);
> D;
[5, 4 : 8] GF(2)-Additive Code over GF(2^2)
Generator matrix:
[  1   0   0   0   1]
[  w   0   0   0   w]
[  0   1   0   0   0]
[  0   w   0   0   1]
[  0   0   1   0   w]
[  0   0   w   0   0]
[  0   0   0   1   1]
[  0   0   0   w   0]
> C subset D;
true
> Q := QuantumCode(C);
> Q;
[[5, 3]] Quantum code over GF(2^2), stabilised by:
[  1   0   w   0   1]
[  w   1   0   w   w]

```

## `Example: symplecticselforthog (ex-937695)`

Any vector over $GF(4)$ will be symplectically orthogonal to itself.

```magma
> V5 := VectorSpace(GF(4), 5);
> { SymplecticInnerProduct(v, v) : v in V5 };
{ 0 }

```
