# Inner Products

Every vector space $V$ in Magma created via the `VectorSpace` intrinsic (or its synonym `KSpace`) has an associated bilinear form which is represented by a matrix and which can be accessed via `InnerProductMatrix(V)` or via the attribute `ip_form`. By default the inner product matrix is the identity. If the dimension of $V$ is $n$, then any $n\times n$ matrix defined over the base field of $V$ can serve as the inner product matrix by passing it to `VectorSpace` as an additional parameter.

If $e_1$, $e_2$, …, $e_n$ is a basis for $V$, the matrix of the form $\beta$ with respect to this basis is $J := \big(\beta(e_i,e_j)\big)$.

## `Example: generalform (ex-2f3d6e)`

```magma
> K := GF(11);
> J := Matrix(K,3,3,[1,2,3, 4,5,6, 7,8,9]);
> V := VectorSpace(K,3,J);
> InnerProductMatrix(V);
[ 1  2  3]
[ 4  5  6]
[ 7  8  9]

```

A vector space $V$ may also have an associated quadratic form. This can be assigned by attaching a matrix to $V$ via the function `QuadraticSpace` described in Section [Quadratic Spaces](constructions.md#subsectquadsp). If assigned, the matrix can be accessed as the return value of `QuadraticFormMatrix`.

The quadratic form defined by the matrix $A$ is $q(v) = vAv^\mathrm{tr}$, and the matrix of its polar form is $A + A^\mathrm{tr}$. It is always possible to represent a quadratic form by an upper triangular matrix. Furthermore, if the characteristic of the field is not two, the quadratic form may be represented by the symmetric matrix ${1\over 2}J$, where $J$ is the matrix of its polar form.

In order to accommodate hermitian forms, a vector space of type `ModTupFld` has an attribute `Involution`. This attribute is intended to hold an automorphism (of order two) of the base field.

## `EnsureUpperTriangular(A): AlgMatElt -> AlgMatElt`

Given an $n\times n$ matrix $A$ this function returns the upper triangular matrix $Q$ which represents the same quadratic form as $A$. That is, for all $n$-tuples $v$ we have $vAv^\mathrm{tr}= vQv^\mathrm{tr}$.

## `DotProduct(u, v): ModTupFldElt, ModTupFldElt -> FldElt`

If $V$ is the generic space of the parent of $u$ and $v$, let $\sigma$ be the field automorphism `V`Involution` if this attribute is assigned or the identity automorphism if `V`Involution` is not assigned. If $J$ is the inner product matrix of $V$, the expression `DotProduct(u,v)` evaluates to $uJ\sigma(v^\mathrm{tr})$. That is, it returns $\beta(u,v)$, where $\beta$ is a bilinear or sesquilinear form on $V$.

## `DotProductMatrix(S): SeqEnum[ModTupFldElt] -> AlgMatElt`

The matrix of inner products of the vectors in the sequence $S$. The inner products are calculated using `DotProduct` and therefore take into account any field automorphism attached to the `Involution` attribute of the generic space of the universe of $S$.

## `GramMatrix(V): ModTupRng -> AlgMatElt`

If $B$ is the basis matrix of $V$ and if $J$ is the inner product matrix, this function returns $BJB^{\hbox{tr}}$. In this case the `Involution` attribute is ignored.

## `InnerProductMatrix(V): ModTupRng -> AlgMatElt`

The inner product matrix attached to the generic space of $V$. This is the attribute `V`ip_form`.

## `Example: grammatrix (ex-9d71da)`

This example illustrates the difference between `GramMatrix` and `InnerProductMatrix`. The function `GramMatrix` uses the echelonised basis of the subspace $W$. To obtain the matrix of inner products between a given list of vectors, use `DotProductMatrix`.

```magma
> K<a> := QuadraticField(-2);
> J := Matrix(K,3,3,[1,2,1, 2,1,0, 1,0,2]);
> V := VectorSpace(K,3,J);
> W := sub<V| [a,a,a], [1,2,3]>;
> InnerProductMatrix(W);
[1 2 1]
[2 1 0]
[1 0 2]
> GramMatrix(W);
[1 0]
[0 9]
> DotProductMatrix([W.1,W.2]);
[ -20 19*a]
[19*a   37]

```

## `Example: innerprod (ex-af15e4)`

Continuing the previous example, the vector space $V$ does not have the attribute `Involution` assigned and therefore `DotProduct` uses the *symmetric* bilinear form represented by the inner product matrix $J$. However, the field $K$ has a well-defined operation of complex conjugation and so `InnerProduct` uses the *hermitian* form represented by $J$.

```magma
> u := W.1+W.2;
> DotProduct(u,u);
38*a + 17
> InnerProduct(u,u);
57

```

## Orthogonality

If $\beta$ is any bilinear or sesquilinear form, the vectors $u$ and $v$ are *orthogonal* if $\beta(u,v) = 0$. The *left orthogonal complement* of a subset $X$ of $V$ is the subspace

$$
{}^\perp X := \{\,u \in V \mid \beta(u,x) = 0\text{ for all }x\in X\,\}
$$

and the *right orthogonal complement* of $W$ is

$$
X^\perp := \{\,u \in V \mid \beta(x,u) = 0\text{ for all }x\in X\,\}.
$$

If $\beta$ is reflexive, then ${}^\perp X = X^\perp$.

### `OrthogonalComplement(V, X : parameters): ModTupFld, ModTupFld -> ModTupFld`

```magma
Right: BoolElt                    Default: false
```

The default value is the left orthogonal complement of $X$ in $V$. To obtain the right orthogonal complement set `Right` to `true`.

### `Radical(V : parameters): ModTupFld -> ModTupFld`

```magma
Right: BoolElt                    Default: false
```

The left radical of the inner product space $V$, namely ${}^\perp V$. To obtain the right radical set `Right` to `true`.

A bilinear or sesquilinear form $\beta$ is *non-degenerate* if $\hbox{rad}(V) = 0$, where $V$ is the polar space of $\beta$.

### `IsNondegenerate(V): ModTupFld -> BoolElt`

Returns `true` if the determinant of the matrix of inner products of the basis vectors of $V$ is non-zero, otherwise `false`. This function takes into account the field automorphism, if any, attached to the `Involution` attribute of the generic space of $V$.

### `IsDegenerate(V): ModTupFld -> BoolElt`

The opposite of the above.

If $V$ is a quadratic space over a perfect field of characteristic 2, the restriction of the quadratic form $Q$ to the radical is a semilinear functional (with respect to $x \mapsto x^2$) whose kernel is the *singular radical* of $V$. A quadratic space is *non-singular* if its singular radical is zero.

### `SingularRadical(V): ModTupFld -> ModTupFld`

The kernel of the restriction of the quadratic form of the quadratic space $V$ to the radical of $V$.

### `IsNonsingular(V): ModTupFld -> BoolElt`

Returns `true` if $V$ is a non-singular quadratic space, otherwise `false`.
