# Creation of Quaternion Orders

Let $R$ be a ring with field of fractions $K$, and let $A$ be a quaternion algebra over $K$. An $R$-*order* in $A$ is a subring $O \subset A$ which is a $R$-submodule of $A$ with $O\cdot K = A$. An order is *maximal* if it is not properly contained in any other order.

One can create orders for number rings $R$, for $R = {\mathbb{Z}}$ or for $R=k[x]$ with $k$ a field. Unlike commutative orders, it is important to note that maximal orders $O$ of quaternion algebras are no longer unique: for any $x \in A$ not in the normalizer of $O$, we have another maximal order given by $O'=x^{-1} O x \neq O$.

When $R={\mathbb{Z}}$ or $R=k[x]$, the order $O$ has type `AlgQuatOrd`. When $R$ inherits from type `RngOrd` (a number ring), the order $O$ has type `AlgAssVOrd`; see Section [Orders](../AssociativeAlgebras/alg_ass_ord.md#secalgassvord) for more information on constructors and general procedures for these orders.

See above ([Introduction](introduction.md#algquat-important-warning)) for an important warning regarding quaternion algebras over the rationals.

## Creation of Orders from Elements

The creation of orders from elements of number rings is covered in Section [Orders](../AssociativeAlgebras/alg_ass_ord.md#secalgassvord). The creation of quaternion orders over the integers and univariate polynomial rings is covered in this section.

### `QuaternionOrder(S): [AlgQuatElt] -> AlgQuatOrd`

```magma
IsBasis: BoolElt                    Default: false
```

Given $S$ a sequence of elements in a quaternion algebra defined over ${\mathbb{Q}}$ or ${\mathbb{F}}_q(X)$, this function returns the order generated by $S$ over ${\mathbb{Z}}$ or ${\mathbb{F}}_q[X]$. If the set $S$ does not generate an order, an error will be returned. If the parameter `IsBasis` is set to `true` then $S$ will be used as the basis of the order returned.

### `QuaternionOrder(R, S): Rng, [AlgQuatElt] -> AlgQuatOrd`

### `Order(R, S): Rng, [AlgQuatElt] -> AlgQuatOrd`

```magma
Check: BoolElt                    Default: true
```

Given a ring $R$ and a sequence $S$ of elements of a quaternion algebra over ${\mathbb{Q}}$ or ${\mathbb{F}}_q(X)$, this function returns the $R$-order with basis $S$. The sequence must have length four.

### `Example: Quaternion Orders Over Q FqX (ex-b0f32f)`

First we construct an order over a polynomial ring.

```magma
> K<t> := FunctionField(FiniteField(7));
> A<i,j,k> := QuaternionAlgebra< K | t, t^2+t+1 >;
> O := QuaternionOrder( [i,j] );
> Basis(O);
[1, i, j, k ]

```

Next we demonstrate how to construct orders in quaternion algebras generated by a given sequence of elements. When provided with a sequence of elements of a quaternion algebra over ${\mathbb{Q}}$, Magma reduces the sequence so as to form a basis. When provided with the ring over which these elements are to be interpreted, the sequence must be a basis with initial element $1$, and the order having this basis is constructed.

```magma
> A<i,j,k> := QuaternionAlgebra< RationalField() | -1, -3 >;
> B := [ 1, 1/2 + 1/2*j, i, 1/2*i + 1/2*k ];
> O := QuaternionOrder(B);
> Basis(O);
[ 1, 1/2*i + 1/2*k, 1/2 - 1/2*j, -1/2*i + 1/2*k ]
> S := QuaternionOrder(Integers(),B);
> Basis(S);
[ 1, 1/2 + 1/2*j, i, 1/2*i + 1/2*k ]

```

## Creation of Maximal Orders

### `MaximalOrder(A): AlgQuat[FldRat] -> AlgQuatOrd`

### `MaximalOrder(A): AlgQuat[FldFunRat] -> AlgQuatOrd`

### `MaximalOrder(A): AlgQuat[FldOrd] -> AlgAssVOrd`

### `MaximalOrder(A): AlgQuat[FldNum] -> AlgAssVOrd`

A maximal order is constructed in the quaternion algebra $A$. The algebra $A$ must be defined over a field $K$ where $K$ is either a number field, ${\mathbb{Q}}$, ${\mathbb{F}}_q(X)$ with $q$ odd, or the field of fractions of a number ring. Over ${\mathbb{F}}_q(X)$ we use the standard algorithm [[Friedrichs, 1997](../../references.md#cite-fr1), [Ivanyos and Rónyai, 1993](../../references.md#cite-ivanyos-ronyai)]. Over the rationals or over a number field, we use a variation of this algorithm optimized for the case of quaternion algebras. First, a factorization of the discriminant of a tame order (see below) is computed. Then, for each prime $p$ dividing the discriminant, a $p$-maximal order compatible with the existing order is computed. The method used corresponds to Algorithm 4.3.8 in [[Voight, 2005](../../references.md#cite-voight1)]. See also [[Voight, 2011](../../references.md#cite-voight3)].

### `Example: Quaternion MaximalOrder (ex-9b04e9)`

The following is an example of a quaternion algebra which is unramified at all finite primes.

```magma
> P<x> := PolynomialRing(Rationals());
> F<b> := NumberField(x^3-3*x-1);
> A<alpha,beta,alphabeta> := QuaternionAlgebra<F | -3,b>;
> O := MaximalOrder(A);
> Factorization(Discriminant(O));
[]

```

Hence the algebra $A$ has a maximal order of discriminant $1$, or equivalently, $A$ is unramified at all finite places of $F$.

Since we are working over a general order of a number field, we can no longer guarantee that an order will have a free basis, so it must be represented by a pseudomatrix. For more on pseudomatrices, see Section [Pseudo Matrices](../../Modules/ModulesOverDedekindDomains/pmat.md#secpmat).

```magma
> Z_F := BaseRing(O);
> PseudoBasis(O);
[
    <Principal Ideal of Z_F
    Generator:
        Z_F.1, Z_F.1>,
    <Fractional Ideal of Z_F
    Two element generators:
        Z_F.1
        2/3*Z_F.1 + 1/6*Z_F.2 + 1/6*Z_F.3, 3/1*Z_F.1 + i>,
    <Principal Ideal of Z_F
    Generator:
        Z_F.1, j>,
    <Fractional Ideal of Z_F
    Two element generators:
        Z_F.1
        11/2*Z_F.1 + 1/6*Z_F.2 + 35/6*Z_F.3, 3/1*Z_F.1 - i + 3/1*Z_F.1*j + k>
]

```

The wide applicability of the above algorithm, is demonstrated by examining a “random” quaternion algebra over a “random” quadratic number field.

```magma
> for c := 1 to 10 do
>   D := Random([d : d in [-100..100] | not IsSquare(d)]);
>   K<w> := NumberField(x^2-D);
>   Z_K := MaximalOrder(K);
>   K<K1,w> := FieldOfFractions(Z_K);
>   a := Random([i : i in [-50..50] | i ne 0]) + Random([-50..50])*w;
>   b := Random([i : i in [-50..50] | i ne 0]) + Random([-50..50])*w;
>   printf "D = %o, a = %o, b = %o\n", D, a, b;
>   A := QuaternionAlgebra<K | a,b>;
>   O := MaximalOrder(A);
>   ds := [<pp[1],pp[2],HilbertSymbol(A,pp[1])> :
>            pp in Factorization(Discriminant(O))];
>   print ds;
>   for d in ds do
>     if d[3] eq 1 then
>       break c;
>     end if;
>   end for;
> end for;
D = 5, a = -46/1*K1 + 25/1*w, b = -10/1*K1 - 7/1*w
[
    <Prime Ideal of Z_K
    Two element generators:
        [31, 0]
        [5, 2], 2, -1>,
    <Prime Ideal of Z_K
    Two element generators:
        [11, 0]
        [6, 2], 2, -1>
]
...

```

For each such “random” quaternion algebra, we verify that the Hilbert symbol evaluated at each prime dividing the discriminant of the maximal order is $-1$, indicating that the algebra is indeed ramified at the prime.

### `MaximalOrder(O): AlgQuatOrd -> AlgQuat`

### `MaximalOrder(O): AlgAssVOrd[RngOrd] -> AlgAssVOrd`

For $O$ a quaternion order defined over ${\mathbb{Z}}$, ${\mathbb{F}}_q[X]$ with $q$ odd or a number ring, this function returns a maximal order containing $O$.

### `pMaximalOrder(O, p): AlgQuatOrd, RngElt -> AlgQuatOrd, RngIntElt`

### `pMaximalOrder(O, p): AlgAssVOrd, RngOrdIdl -> AlgAssVOrd, RngIntElt`

For $O$ a quaternion order defined over ${\mathbb{Z}}$, ${\mathbb{F}}_q[X]$ with $q$ odd or a number ring and a prime (ideal) $p$, this function returns a $p$-maximal order $O'$ containing the order $O$. The $p$-adic valuation of the discriminant of $O'$ (which is either $0$ or $1$) is returned as a second return value.

### `TameOrder(A): AlgQuat[FldAlg] -> AlgAssVOrd`

Given a quaternion algebra $A$, this function returns an order $O$ having the property that the odd reduced discriminant of $O$ is squarefree. The algebra $A$ must be defined over a number field or field of fractions of a number ring. The algorithm ignores even primes and does not test the remaining odd primes for maximality.

## Creation of Orders with given Discriminant

The following two functions together with the maximal order algorithms of the previous subsection allow the construction of arbitrary Eichler orders.

### `Order(O, N): AlgQuatOrd, RngElt -> AlgQuatOrd`

Given an order $O$ in a quaternion algebra $A$ over the rationals or ${\mathbb{F}}_q(x)$ with $q$ odd, and some element $N$ in the base ring of $O$, this function returns a suborder $O'$ of $O$ having index $N$. Currently, $N$ and the level of $O$ must be coprime and $N$ must have valuation at most $1$ at each ramified prime of $A$. The order $O'$ is locally Eichler at all prime divisors of $N$ that are not ramified in $A$. In particular, if $O$ is Eichler and $N$ is coprime to the discriminant of $A$, so is $O'$.

### `Order(O, N): AlgAssVOrd, RngOrdIdl -> AlgAssVOrd`

Given a maximal quaternion order $O$ over a number ring, this function returns an Eichler order of level $N$ inside $O$.

### `GorensteinClosure(O): AlgAssVOrd -> AlgAssVOrd, .`

Let $O$ be a quaternion order over $R$. There exists a unique Gorenstein order $\Lambda$ over $R$ such that $\Lambda$ is generated by $1$ and $bO$ for some integral ideal $b$ of $R$. The order $\Lambda$ and the ideal $b$ are called the Gorenstein closure and the Brandt invariant of $O$ respectively.

The first return value of this intrinsic is the Gorenstein closure of $O$.

The second return value is either a positive or monic generator of $b$ or $b$ itself depending on whether $R$ is ${\mathbb{Z}}$, ${\mathbb{F}}_q[x]$ or a number ring.

### `Example: Quaternion Orders (ex-966516)`

First we construct a quaternion algebra $A$ over ${\mathbb{F}}_5(x)$ ramified at $x^2+x+1$, then a maximal order $M$ in $A$ and finally an Eichler $O$ order of discriminant $(x^2+x+1)(x^3+x+1)^5$.

```magma
> P<x> := PolynomialRing(GF(5));
> A := QuaternionAlgebra(x^2+x+1);
> M := MaximalOrder(A);
> O := Order(M, (x^3+x+1)^5);
> FactoredDiscriminant(O);
[
    <x^2 + x + 1, 1>,
    <x^3 + x + 1, 5>
]

```

## Creation of Orders with given Discriminant over the Integers

When constructing quaternion orders over the integers, several shortcuts are available.

### `QuaternionOrder(A, M): AlgQuat[FldRat], RngIntElt -> AlgQuatOrd`

Given a quaternion algebra $A$ and a positive integer $M$, this function returns an order of index $M$ in a maximal order of the quaternion algebra $A$ defined over ${\mathbb{Q}}$. The second argument $M$ can have at most valuation $1$ at any ramified prime of $A$.

### `QuaternionOrder(N): RngIntElt -> AlgQuatOrd`

### `QuaternionOrder(N, M): RngIntElt, RngIntElt -> AlgQuatOrd`

Given positive integers $N$ and $M$, this function returns an order of index $M$ in a maximal order of the rational quaternion algebra $A$ of discriminant $N$. The discriminant $N$ must be a product of an odd number of distinct primes, and the argument $M$ can be at most of valuation 1 at any prime dividing $N$. If $M$ is omitted, the integer $M$ defaults to $1$, i.e., the function will return a maximal order.

### `QuaternionOrder(D1, D2, T): RngIntElt, RngIntElt, RngIntElt -> AlgQuat`

This intrinsic constructs the quaternion order ${\mathbb{Z}}\langle x,y\rangle$, where ${\mathbb{Z}}[x]$ and ${\mathbb{Z}}[y]$ are quadratic subrings of discriminant $D_1$ and $D_2$, respectively, and ${\mathbb{Z}}[xy - yx]$ is a quadratic subring of discriminant $D_1 D_2 - T^2$.

Note that the container algebra of such a quaternion order is **not** usually in standard form (see the example below).

### `Example: Quaternion Orders Over The Integers (ex-f04e9e)`

The above constructors permit the construction of Eichler orders over ${\mathbb{Z}}$, if the discriminant $N$ and the index $M$ are coprime. More generally they allow the construction of an order whose index in an Eichler order divides the discriminant.

```magma
> A := QuaternionOrder(103,2);
> Discriminant(A);
206
> Factorization($1);
[ <2, 1>, <103, 1> ]
> _<x> := PolynomialRing(Rationals());
> [MinimalPolynomial(A.i) : i in [1..4]];
[
    x - 1,
    x^2 + 1,
    x^2 - x + 52,
    x^2 + 104
]

```

The constructor `QuaternionOrder(D1, D2, T)` may return an order whose container algebra is not in standard form.

```magma
> A := QuaternionOrder(-4, 5, 2);
> B := Algebra(A);
> B.1 * B.2 eq - B.2 * B.1;
false

```
