---
title: "Inner Products and Duals"
canonical: "https://docs.magma-maths.org/v2.30-1/CodingTheory/QuantumCodes/inner-products.html"
source: "https://docs.magma-maths.org/v2.30-1/CodingTheory/QuantumCodes/inner-products.md"
part: "Coding Theory"
chapter: "Quantum Codes"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Coding Theory", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/index-coding-theory.md"}
  - {"title": "Quantum Codes", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/QuantumCodes/index-quantum-codes.md"}
prev: {"title": "Access Functions", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/QuantumCodes/access.md"}
next: {"title": "Weight Distribution and Minimum Weight", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/QuantumCodes/weight-distribution.md"}
intrinsics:
  - {"name": "SymplecticInnerProduct", "signature": "SymplecticInnerProduct(v1, v2): ModTupFldElt, ModTupFldElt -> FldFinElt"}
  - {"name": "SymplecticDual", "signature": "SymplecticDual(C): CodeAdd -> CodeAdd"}
  - {"name": "IsSymplecticSelfDual", "signature": "IsSymplecticSelfDual(C): CodeAdd -> BoolElt"}
  - {"name": "IsSymplecticSelfOrthogonal", "signature": "IsSymplecticSelfOrthogonal(C): CodeAdd -> BoolElt"}
examples:
  - "ex-176f6b"
  - "ex-f66c0e"
  - "ex-b98847"
  - "ex-937695"
---

# Inner Products and Duals

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

<a id="function-symplecticinnerproduct-modtupfldelt-modtupfldelt"></a>
## `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](https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/PolarSpaces/index-polar-spaces.md#chappolarspace).

<a id="example-ex-176f6b"></a>
## `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
```

<a id="example-ex-f66c0e"></a>
## `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
```

<a id="function-symplecticdual-codeadd"></a>
## `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)$).

<a id="function-issymplecticselfdual-codeadd"></a>
## `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)$).

<a id="function-issymplecticselforthogonal-codeadd"></a>
## `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)$).

<a id="example-ex-b98847"></a>
## `Example: Symplectically Orthogonal Vectors (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]
```

<a id="example-ex-937695"></a>
## `Example: Symplectic Self-Orthogonality of Vectors (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 }
```
