# Isometries and Similarities

If $\beta$ is a bilinear or sesquilinear form on the vector space $V$, a linear transformation $g$ of $V$ is an *isometry* if $g$ preserves $\beta$; it is a *similarity* if it preserves $\beta$ up to a non-zero scalar multiple.

## Isometries

### `IsIsometry(U, V, f): ModTupFld, ModTupFld, Map -> BoolElt`

Returns `true` if the map $f$ is an isometry from $U$ to $V$ with respect to the attached forms.

### `IsIsometry(f): Map -> BoolElt`

Returns `true` if the map $f$ is an isometry from its domain to its codomain.

### `IsIsometry(V, g): ModTupFld, Mtrx -> BoolElt`

Returns `true` if the matrix $g$ is an isometry of $V$ with respect to the attached form.

### `IsIsometric(V, W): ModTupFld, ModTupFld -> BoolElt, Map`

Determines whether the polar spaces $V$ and $W$ are isometric; if they are, an isometry is returned (as a map).

### `Example: isometric (ex-9909e6)`

A vector space is always equipped with a bilinear form and the default value is the identity matrix. However the “standard” symmetric form is $Q+Q^{\hbox{tr}}$, where $Q$ is the standard quadratic form. In the following example the polar spaces defined by these forms are similar but not isometric.

```magma
> F := GF(5);
> V1 := VectorSpace(F,5);
> PolarSpaceType(V1);
orthogonal space
> WittIndex(V1);
2
> J2 := StandardSymmetricForm(5,F);
> J2;
[0 0 0 0 1]
[0 0 0 1 0]
[0 0 2 0 0]
[0 1 0 0 0]
[1 0 0 0 0]
> V2 := VectorSpace(F,5,J2);
> IsIsometric(V1,V2);
false
> V3 := VectorSpace(F,5,2*J2);
> flag, f := IsIsometric(V1,V3); flag;
true
> IsIsometry(f);
true

```

If $J$ is an $n\times n$ matrix which represents a bilinear form and if $M$ is a non-singular $n\times n$ matrix, then $J$ and $MJM^{\hbox{tr}}$ are said to be *congruent* and they define isometric polar spaces.

Conversely, given bilinear forms $J_1$ and $J_2$ the following example shows how to use the `IsIsometric` function to determine whether $J_1$ and $J_2$ are congruent and if so how to find a matrix $M$ such that $J_1 = MJ_2M^{\hbox{tr}}$.

### `Example: transform (ex-5a3a59)`

Begin with alternating forms $J_1$ and $J_2$ over ${\bf F}_{25}$, construct the corresponding symplectic spaces and then use the isometry to define the matrix $M$.

```magma
> F<x> := GF(25);
> J1 := Matrix(F,4,4,[ 0, x^7, x^14, x^13, x^19, 0, x^8, x^5,
>   x^2, x^20, 0, x^17, x, x^17, x^5, 0 ]);
> J2 := Matrix(F,4,4,[ 0, x^17, 2, x^23, x^5, 0, x^15, x^5,
>   3, x^3, 0, 4, x^11, x^17, 1, 0 ]);
> V1 := SymplecticSpace(J1);
> V2 := SymplecticSpace(J2);
> flag, f := IsIsometric(V1,V2); assert flag;
> f;
Mapping from: ModTupFld: V1 to ModTupFld: V2 given by a rule
> M := Matrix(F,4,4,[f(V1.i) : i in [1..4]]);
> J1 eq M*J2*Transpose(M);
true

```

### `Example: transformalt (ex-6727c3)`

Another way to obtain a matrix with the same effect as $M$ is to use the function `TransformForm`.

```magma
> M1 := TransformForm(J1,"symplectic");
> M2 := TransformForm(J2,"symplectic");
> M_alt := M1*M2^-1;
> J1 eq M_alt*J2*Transpose(M_alt);
true

```

### `CommonComplement(V, U, W): ModTupFld, ModTupFld, ModTupFld -> ModTupFld`

A common complement to the subspaces $U$ and $W$ in the vector space $V$. (The subspaces must have the same dimension.) This is used by the following function, which implements Witt’s theorem.

### `ExtendIsometry(V, U, f): ModTupFld, ModTupFld, Map -> Map`

An extension of the isometry $f : U \to V$ to an isometry $V \to V$, where $U$ is a subspace of the polar space $V$.

This is an implementation of Witt’s theorem on the extension of an isometry defined on a subspace of a symplectic, unitary or quadratic space. The isometry $f$ must satisfy $f(U\cap \hbox{rad}(V)) = f(U)\cap \hbox{rad}(V)$.

If the characteristic is two and the form $J$ of $V$ is symmetric, then $J$ must be alternating.

### `IsometryGroup(V): ModTupFld -> GrpMat`

The group of isometries of the polar space $V$. This includes degenerate polar spaces as well as polar spaces defined by a quadratic form over a field of characteristic two.

Given a reflexive form $J$, the function `IsometryGroup(J)` defined in Chapter [Algebras with Involution](../../Algebras/AlgebrasWithInvolution/index-algebras-with-involution.md#chapstaralgebras) returns the isometry group of $J$. More generally, if $S$ is a sequence of reflexive forms, the function `IsometryGroup(S)` returns the group of isometries of the system.

### `Example: isometrygroup (ex-833a77)`

We give an example of an isometry group of a degenerate quadratic space over a field of characteristic 2.

```magma
> F := GF(4);
> Q1 := StandardQuadraticForm(4,F : Minus);
> Q := DiagonalJoin(Q1,ZeroMatrix(F,2,2));
> V := QuadraticSpace(Q);
> G := IsometryGroup(V);
> [ IsIsometry(V,g) : g in Generators(G) ];
[ true, true, true, true, true, true, true ]
> #G;
96259276800

```

### `Example: conjisom (ex-86d774)`

The matrix $M$ constructed in Example [Example: transform](#example-ex-5a3a59) can be used to conjugate the isometry group of $J_1$ to the isometry group of $J_2$.

```magma
> F<x> := GF(25);
> J1 := Matrix(F,4,4,[ 0, x^7, x^14, x^13, x^19, 0, x^8, x^5,
>   x^2, x^20, 0, x^17, x, x^17, x^5, 0 ]);
> J2 := Matrix(F,4,4,[ 0, x^17, 2, x^23, x^5, 0, x^15, x^5,
>   3, x^3, 0, 4, x^11, x^17, 1, 0 ]);
> V1 := SymplecticSpace(J1);
> V2 := SymplecticSpace(J2);
> flag, f := IsIsometric(V1,V2); assert flag;
> M := Matrix(F,4,4,[f(V1.i) : i in [1..4]]);
> G1 := IsometryGroup(V1);
> G2 := IsometryGroup(V2);
> M^-1*G1.1*M in G2;
true
> M^-1*G1.2*M in G2;
true

```

## Similarities

If $\beta$ is a bilinear or sesquilinear form, a linear transformation $f$ is a *similarity* with *multiplier* $\lambda$ if $\beta(uf,vf) = \lambda\beta(u,v)$ for all $u,v$.

### `IsSimilarity(U, V, f): ModTupFld, ModTupFld, Map -> BoolElt, FldElt`

Returns `true` if the map $f$ is a similarity from $U$ to $V$ with respect to the attached forms. The second return value is the multiplier.

### `IsSimilarity(f): Map -> BoolElt, FldElt`

Returns `true` if the map $f$ is a similarity from its domain to its codomain. The second return value is the multiplier.

### `IsSimilarity(V, g): ModTupFld, Mtrx -> BoolElt, FldElt`

Returns `true` if the matrix $g$ is a similarity of $V$ with respect to the attached form. The second return value is the multiplier.

### `IsSimilar(V, W): ModTupFld, ModTupFld -> BoolElt, Map`

Determines whether the polar spaces $V$ and $W$ are similar; if they are, a similarity is returned (as a map).

### `Example: simherm (ex-86e68e)`

An example of two unitary spaces, the first defined by an hermitian form, the second by a skew-hermitian form. The spaces are similar but not isometric.

```magma
> F<z> := GF(25);
> sigma := hom< F -> F | x :-> x^5 >;
> J1 := Matrix(F,4,4,[
>    0, z^3, z^14, z^9,   z^15, 2, z^21, z^5,
>    z^22, z^9, 1, z^7,   z^21, z, z^11, 4]);
> J2 := Matrix(F,4,4,[
>    z^15, z^10, z^17, z^7,  z^14, z^15, z^14, z^9,
>    z, z^10, z^3, z^20,     z^23, z^9, z^16, z^21]);
> V1 := UnitarySpace(J1,sigma);
> V2 := UnitarySpace(J2,sigma);
> IsUnitarySpace(V1);
true 1
> IsUnitarySpace(V2);
true -1
> IsIsometric(V1,V2);
false
> flag, f := IsSimilar(V1,V2);
> flag;
true
> IsSimilarity(V1,V2,f);
true z^3

```

### `SimilarityGroup(V): ModTupFld -> GrpMat`

The group of similarities of the polar space $V$. This includes degenerate polar spaces as well as polar spaces defined by a quadratic form over a field of characteristic two.

## Gram-Schmidt Normalisation

Suppose that $\beta$ is a bilinear or sesquilinear form on the vector space $V$ and that $e_1$, …, $e_n$ is an ordered basis for $V$. The Gram matrix $J$ of $\beta$ with respect to this basis is $(\beta(e_i,e_j))$. Changing the basis to $e_1A$, …, $e_nA$ where $A$ is an invertible matrix changes the Gram matrix to the congruent matrix $AJA^{\sigma t}$, where $\sigma$ is a field automorphism. (When the form is symmetric or alternating $\sigma$ is the identity.)

For a positive definite inner product on a real vector space it is possible to choose $A$ so that $AJA^t$ is the identity matrix. The algorithm which achieves this is the *Gram–Schmidt process*.

In general it is possible to choose $A$ so that $D = AJA^{\sigma t}$ is almost diagonal; that is, $D$ is a block diagonal matrix where each block is either a $1\times 1$ block or a $2\times 2$ block $\left(\begin{matrix}0&\alpha\\ s\alpha&0\end{matrix}\right)$, where $s$ is $-1$ if the form is alternating.

The following intrinsic uses the algorithm of Wilson [[Wilson, 2013](../../references.md#cite-wilson2013)].

### `GramSchmidtPair(J): AlgMatElt -> AlgMatElt, AlgMatElt`

Given the matrix $J$ of a reflexive form, apply Wilson’s Gram-Schmidt algorithm to return a pair of matrices $D$ and $A$ such that $AJA' = D$, where $D$ is almost diagonal and $A'$ is either the transposed conjugate of $A$ (when $J$ is hermitian) or the transpose of $A$.

### `Example: hermitiangs (ex-97668f)`

For the case of an hermitian matrix over the Gaussian rationals the algorithm is able to diagonalise the form.

```magma
> F<i> := QuadraticField(-1);
> B := Matrix(F,4,4,[1,0,3-i,2, 0,3,1+i,1+i, 3+i,1-i,0,2, 2,1-i,2,1]);
> B;
[     1      0 -i + 3      2]
[     0      3  i + 1  i + 1]
[ i + 3 -i + 1      0      2]
[     2 -i + 1      2      1]
> D, A := GramSchmidtPair(B);
> D;
[        1         0         0         0]
[        0         3         0         0]
[        0         0     -32/3         0]
[        0         0         0      -5/4]
> A;
[             1              0              0              0]
[             0              1              0              0]
[        -i - 3    1/3*(i - 1)              1              0]
[  1/8*(-i - 4)    1/8*(i - 2) 1/16*(3*i - 7)              1]

```

### `Example: skewgs (ex-7c8257)`

Alternating forms cannot be diagonalised.

```magma
> B := Matrix(Rationals(),4,4,[0,0,3,2, 0,0,1,1, -3,-1,0,2, -2,-1,-2,0]);
> B;
[ 0  0  3  2]
[ 0  0  1  1]
[-3 -1  0  2]
[-2 -1 -2  0]
> D, A := GramSchmidtPair(B);
> D;
[ 0  1  0  0]
[-1  0  0  0]
[ 0  0  0  1]
[ 0  0 -1  0]
> A;
[ 1 -2  0  0]
[ 2 -6  1  0]
[-1  3  0  0]
[ 0  0  0  1]
> A*B*Transpose(A) eq D;
true

```
