# Recognition Functions

A quaternion algebra $A$ over a field $K$ is isomorphic to the matrix ring $M_2(K)$ if and only if there exists a zerodivisor $\epsilon$ in $A$. Given such an $\epsilon$, we can exhibit an explicit isomorphism; otherwise a zerodivisor will be computed first by finding a point on a conic (see [[Vignéras, 1980](../../references.md#cite-vigneras80), Cor. I.2.4]).

Given an associative algebra, we also have an algorithm to recognize if the algebra is a quaternion algebra, and, if so, return an isomorphism to a quaternion algebra in standard form.

## `IsMatrixRing(A): AlgQuat -> BoolElt, AlgMat, Map`

```magma
Isomorphism: BoolElt                    Default: false
```

Returns `true` if and only if the quaternion algebra $A$ with base field $F$ is isomorphic to $M_2(F)$, or equivalently if $A$ has no ramified places. The field $F$ has to be ${\mathbb{Q}}$, ${\mathbb{F}}_q(X)$ (with $q$ odd) or a number field.

If $A$ is isomorphic to $M_2(F)$ and `Isomorphism` is set to `true`, then $M_2(F)$ and an isomorphism $A \to M_2(F)$ are also returned.

## `MatrixRing(A, eps): AlgQuat, AlgQuatElt -> AlgMat, Map`

## `MatrixAlgebra(A, eps): AlgQuat, AlgQuatElt -> AlgMat, Map`

Given a quaternion algebra $A$ and a zerodivisor $\epsilon \in A$, the function returns the matrix algebra $M_2(F)$ and an isomorphism $A \to M_2(F)$.

## `Example: Quaternion MatrixRing (ex-696aa7)`

```magma
> A := QuaternionAlgebra<Rationals() | -1, 1>;
> eps := A.3-1;
> MinimalPolynomial(eps), Norm(eps);
x^2 + 2*x
0

```

Thus, since $\epsilon$ has reduced norm $0$, it is a zerodivisor: indeed, $\epsilon(\epsilon+2)=0$.

```magma
> M2F, phi := MatrixRing(A,eps);
> [<MinimalPolynomial(A.i), MinimalPolynomial(phi(A.i))> : i in [1..3]];
[
    <x^2 + 1, x^2 + 1>,
    <x^2 - 1, x^2 - 1>,
    <x^2 - 1, x^2 - 1>
]

```

## `IsQuaternionAlgebra(B): AlgAss -> BoolElt, AlgQuat, Map`

## `IsQuaternionAlgebra(B): AlgMat -> BoolElt, AlgQuat, Map`

Returns `true` if and only if the associative algebra $B$ is a quaternion algebra; if true, it returns the associated quaternion algebra $A$ in standard form and an algebra homomorphism from $B$ to $A$. The algorithm used is [[Voight, 2005](../../references.md#cite-voight1), Algorithm 4.2.9].

## `Example: Quaternion IsQuaternionAlgebra (ex-52731a)`

We create an associative algebra which is known to be a quaternion algebra $A$ and then recover $A$ (or an isomorphic algebra).

```magma
> A := AssociativeAlgebra(QuaternionAlgebra<Rationals() | -1,1>);
> vecs := [&+[Random(10)*A.i : i in [1..4]] : j in [1..4]];
> Mchange := Matrix(Rationals(),4,4,&cat[Eltseq(vecs[i]) : i in [1..4]]);
> Mchange := Mchange^(-1);
> seq := [<i,j,k,((vecs[i]*vecs[j])*Mchange)[k]> : i,j,k in [1..4]];
> A := AssociativeAlgebra<Rationals(),4 | seq>;
> bl, Aquat, phi := IsQuaternionAlgebra(A);
> bl;
true
> Aquat;
Quaternion Algebra with base ring Rational Field
> Aquat.1^2, Aquat.2^2;
25 -3924/25
> phi;
Mapping from: AlgAss: A to AlgQuat: Aquat given by a rule

```

We now verify the functionality when a zerodivisor is encountered.

```magma
> A := Algebra(MatrixAlgebra(Rationals(),2));
> IsQuaternionAlgebra(A);
true Quaternion Algebra with base ring Rational Field
Mapping from: AlgAss: A to Quaternion Algebra with base ring Rational Field
given by a rule

```

The algebra $k<x,y>$ with $x^2=y^2=xy+yx=0$ is not semisimple; the ideal generated by $x,y$ is a nontrivial two-sided ideal. Similarly, a commutative algebra is not a quaternion algebra.

```magma
> A := Algebra(FPAlgebra<Rationals(), x,y | x^2, y^2, x*y+y*x>);
> IsQuaternionAlgebra(A);
false
> A := Algebra(FPAlgebra<Rationals(), x | x^4+x^2+1>);
> IsQuaternionAlgebra(A);
false

```

In characteristic $2$, the algorithm also performs correctly, both for an associative but non-quaternion algebra and for the “universal” example of a quaternion algebra.

```magma
> A := Algebra(FPAlgebra<GF(2), x,y | x^2, y^2, x*y+y*x+1>);
> IsQuaternionAlgebra(A);
false
> F<a,b,x,y,z,w> := FieldOfFractions(PolynomialRing(GF(2),6));
> M := [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],
>       [0,1,0,0],[a,1,0,0],[0,0,0,1],[0,0,a,1],
>       [0,0,1,0],[0,0,1,1],[b,0,0,0],[b,b,0,0],
>       [0,0,0,1],[0,0,a,0],[0,b,0,0],[a*b,0,0,0]];
> A<alpha,beta> := AssociativeAlgebra<F,4 | M>;
> alpha^2+alpha+a;
(0 0 0 0)
> beta^2+b;
(0 0 0 0)
>
> bl, Aquat, phi := IsQuaternionAlgebra(A);
> bl;
true
> Aquat;
Quaternion Algebra with base ring Multivariate rational function field of
rank 6 over GF(2)
> theta := phi(x+y*alpha+z*beta+w*alpha*beta);
> Trace(theta);
y
> Norm(theta);
a*b*w^2 + a*y^2 + b*z^2 + b*z*w + x^2 + x*y

```

## `MatrixRepresentation(A): AlgQuat -> Map`

## `MatrixRepresentation(R): AlgQuatOrd -> Map`

Given a quaternion algebra $A$ over ${\mathbb{Q}}$ or a quaternion order $R$ over ${\mathbb{Z}}$, this function returns a $2 \times 2$-matrix representation of $A$, defined over a quadratic extension.
