# Class Groups

In Magma, the class group of binary quadratic forms of discriminant $D$ is defined by the equivalence relation `IsEquivalent(f1, f2 : Narrow := false)` for forms `f1, f2`. It is the same as the ideal class group (`PicardGroup`) of the quadratic order of discriminant $D$. The class group of binary forms for $D > 0$ is usually defined using standard (“narrow”) equivalence of forms, which agrees with the narrow ideal class group of the order. For $D < 0$, there is no difference. For $D > 0$, the two class groups differ if and only if all units in the quadratic order have norm $1$. When they are different, each class is the union of two narrow classes: forms $\langle a,b,c \rangle$ and $\langle -a,b,-c \rangle$ are equivalent but not narrowly equivalent.

## `ClassNumber(Q: parameters): QuadBin -> RngIntElt`

## `ClassNumber(D: parameters): RngIntElt -> RngIntElt`

```magma
Al              : MonStgElt                    Default: "Automatic"
FactorBasisBound: FldReElt                     Default: 0.1
ProofBound      : FldReElt                     Default: 6
ExtraRelations  : RngIntElt                    Default: 1
```

This returns the class number of binary quadratic forms $Q$ of discriminant $D$.

The parameter `Al` may be supplied to select the method used to calculate the class number. The possible values are `"ReducedForms"` (enumerating all reduced forms), `"Shanks"` (using a Shanks-based algorithm in the class group), `"Sieve"` or `"NoSieve"`. The default is to use reduced form enumeration for small discriminants, the Shanks algorithm for the middle range, a class group index-calculus for large discriminants and the sieve method described in [[Jacobson, Jr., 1999](../../references.md#cite-jacobson)] for very large discriminants.

The parameters `FactorBasisBound`, `ProofBound` and `ExtraRelations` are relevant only for the index calculus algorithm. They are described (below) under [`ClassGroup`](#function-quadbin-classgroup).

## `ClassGroup(Q: parameters): QuadBin -> GrpAb, Map`

```magma
Al              : MonStgElt                    Default: "Automatic"
FactorBasisBound: FldReElt                     Default: 0.1
ProofBound      : FldReElt                     Default: 6
ExtraRelations  : RngIntElt                    Default: 1
```

This computes the class group of binary quadratic forms of discriminant $D$. The function returns the class group as an abelian group, together with a map from the group to quadratic forms.

**Important:** the class group is defined using non-strict equivalence (see the introduction to this subsection).

Depending on the size of $D$, either a Shanks-based method is used ([[Buchmann *et al.*, 1997](../../references.md#cite-teske-bsgs), [Teske, 1998](../../references.md#cite-teske-prho)]), an index calculus variant ([[Cohen *et al.*, 1993](../../references.md#cite-cohdiol), [Cohen, 1993](../../references.md#cite-cohen1), [Hafner and McCurley, 1989](../../references.md#cite-hafnermccurley)]) or a sieving method ([[Jacobson, Jr., 1999](../../references.md#cite-jacobson)]). If the parameter `Al` is set to `"Sieve"` or $D$ is larger than $10^{20},$ then the sieving method is used. The results are only proven under GRH. If the parameter `Al` is set to `"NoSieve"` then the sieving method will not be used.

The parameters `FactorBasisBound`, `ProofBound` and `ExtraRelations` apply to the index calculus method only. This method performs two steps. In the first step a factor basis containing prime forms of norm $< B_1$ is built. Next, one looks for generators for the full lattice of relations between the forms in the factor basis. The determinant of this lattice will be the class number and the Smith-form of the relation matrix gives the structure of the class group. Once the matrix is of full rank, the algorithm will look for `ExtraRelations` more relations to potentially decrease the discriminant. In the second step, for all prime forms of norm $< B_2$ it is verified that they are in the class group generated by the forms of the first step. The bounds are chosen to be $B_1 :=$ `FactorBasisBound`$\cdot \log^2 |D|$ and $B_2 :=$ `ProofBound`$\cdot \log^2 |D|$, so the result is correct under the assumption of GRH. The final result is then checked against the Euler product over the first $30000$ primes. If the quotient becomes too large, a warning is issued. In this case one should increase the `ExtraRelations` parameter.

## `ClassGroupStructure(Q: parameters): QuadBin -> [ RngIntElt ]`

The structure of the class group of the binary quadratic forms $Q$ of discriminant $D$ returned as a sequence of integers giving the abelian invariants.

The parameters are the same as for `ClassGroup`.

## `AmbiguousForms(Q): QuadBin -> SeqEnum`

Enumerates the ambiguous forms of negative discriminant $D$, where $D$ is the discriminant of the magma of binary quadratic forms $Q$.

## `TwoTorsionSubgroup(Q): QuadBin -> GrpAb, Map`

The subgroup of 2–torsion elements of in the class group of $Q$.

## `Example: Forms (ex-d1a38f)`

We give an example of some computations in the class group of a magma of quadratic forms. Elements in the class group are not really represented by single reduced forms but by cycles of equivalent reduced forms.

```magma
> Q<z> := QuadraticField(7537543);                        // arbitrary choice
> Q := QuadraticForms(Discriminant(Q));
> C, m := ClassGroup(Q);
> C;
Abelian Group isomorphic to Z/2 + Z/76
Defined on 2 generators
Relations:
    76*C.1 = 0
    2*C.2 = 0
>                                    // get the generators as quadratic forms:
> f := m(C.1);
> g := m(C.2);
> h := g^2;
> g, h;
<-1038,4894,1493> <-887,4340,3189>
> c := [];                     // create the cycle of forms equivalent to g^2:
> repeat
>     h := ReductionStep(h);
>     Append(~c, h);
> until h eq g^2;
> P := Parent(g);
> Identity(P) in c;
true                 // this proves that the second class has order dividing 2
> for d in Divisors(76) do
>     c := [];
>     h := f^d;
>     repeat h := ReductionStep(h); Append(~c, h);
>     until h eq f^d;
>     d, Identity(P) in c, #c;
> end for;
1 false 16
2 false 14
4 false 12                           // the cycle lengths vary
19 false 18
38 false 16
76 true 14                           // so the true order of this class is 76

```
