# Gauss composition law

In mathematics, in number theory, Gauss composition law is a rule, invented by Carl Friedrich Gauss, for performing a binary operation on integral binary quadratic forms (IBQFs). Gauss presented this rule in his Disquisitiones Arithmeticae, a textbook on number theory published in 1801, in Articles 234 - 244. Gauss composition law is one of the deepest results in the theory of IBQFs and Gauss's formulation of the law and the proofs its properties as given by Gauss are generally considered highly complicated and very difficult. Several later mathematicians have simplified the formulation of the composition law and have presented it in a format suitable for numerical computations. The concept has also found generalisations in several directions.

## Integral binary quadratic forms

An expression of the form $Q(x,y)=\alpha x^{2}+\beta xy+\gamma y^{2}$, where $\alpha ,\beta ,\gamma ,x,y$ are all integers, is called an integral binary quadratic form (IBQF). The form $Q(x,y)$ is called a primitive IBQF if $\alpha ,\beta ,\gamma$ are relatively prime. The quantity $\Delta =\beta ^{2}-4\alpha \gamma$ is called the discriminant of the IBQF $Q(x,y)$. An integer $\Delta$ is the discriminant of some IBQF if and only if $\Delta \equiv 0,1(\mathrm {mod} \,\,4)$. $\Delta$ is called a fundamental discriminant if and only if one of the following statements holds
* $\Delta \equiv 1\,\,(\mathrm {mod} \,\,4)$ and is square-free,
* $\Delta =4m$ where $m=2{\text{ or }}3\,\,(\mathrm {mod} \,\,4)$ and $m$ is square-free.
If $\Delta <0$ and $\alpha >0$ then $Q(x,y)$ is said to be positive definite; if $\Delta <0$ and $\alpha <0$ then $Q(x,y)$ is said to be negative definite; if $\Delta >0$ then $Q(x,y)$ is said to be indefinite.

### Equivalence of IBQFs

Two IBQFs $g(x,y)$ and $h(x,y)$ are said to be equivalent (or, properly equivalent) if there exist integers α, β, γ, δ such that
    $\alpha \delta -\beta \gamma =1$ and $g(\alpha x+\beta y,\gamma x+\delta y)=h(x,y).$
The notation $g(x,y)\sim h(x,y)$ is used to denote the fact that the two forms are equivalent. The relation "$\sim$" is an equivalence relation in the set of all IBQFs. The equivalence class to which the IBQF $g(x,y)$ belongs is denoted by $[g(x,y)]$.
Two IBQFs $g(x,y)$ and $h(x,y)$ are said to be improperly equivalent if
    $\alpha \delta -\beta \gamma =-1$ and $g(\alpha x+\beta y,\gamma x+\delta y)=h(x,y).$
The relation in the set of IBQFs of being improperly equivalent is also an equivalence relation.
It can be easily seen that equivalent IBQFs (properly or improperly) have the same discriminant.

## Gauss's formulation of the composition law
### Historical context

The following identity, called Brahmagupta identity, was known to the Indian mathematician Brahmagupta (598–668) who used it to calculate successively better fractional approximations to square roots of positive integers:
    $(x^{2}+Dy^{2})(u^{2}+Dv^{2})=(xu+Dyv)^{2}+D(xv-yu)^{2}$
Writing $f(x,y)=x^{2}+Dy^{2}$ this identity can be put in the form
    $f(x,y)f(u,v)=f(X,Y)$ where $X=xu+Dyv,Y=xv-yu$.
Gauss's composition law of IBQFs generalises this identity to an identity of the form $g(x,y)h(u,v)=F(X,Y)$ where $g(x,y),h(x,y),F(X,Y)$ are all IBQFs and $X,Y$ are linear combinations of the products $xu,xv,yu,yv$.

### The composition law of IBQFs

Consider the following IBQFs:
    $g(x,y)=ax^{2}+bxy+cy^{2}$
    $h(x,y)=dx^{2}+exy+fy^{2}$
    $F(x,y)=Ax^{2}+Bxy+Cy^{2}$
If it is possible to find integers $p,q,r,s$ and $p^{\prime },q^{\prime },r^{\prime },s^{\prime }$ such that the following six numbers
    $pq^{\prime }-qp^{\prime },pr^{\prime }-rp^{\prime },ps^{\prime }-sp^{\prime },qr^{\prime }-rq^{\prime },qs^{\prime }-sq^{\prime },rs^{\prime }-sr^{\prime }$
have no common divisors other than ±1, and such that if we let
    $X=pxu+qxv+ryu+syv$
    $Y=p^{\prime }xu+q^{\prime }xv+r^{\prime }yu+s^{\prime }yv$
the following relation is identically satisfied
    $g(x,y)h(u,v)=F(X,Y)$,
then the form $F(x,y)$ is said to be a composite of the forms $g(x,y)$ and $h(x,y)$. It may be noted that the composite of two IBQFs, if it exists, is not unique.

### Example

Consider the following binary quadratic forms:
    $g(x,y)=2x^{2}+3xy-10y^{2}$
    $h(x,y)=5x^{2}+3xy-4y^{2}$
    $F(x,y)=10x^{2}+3xy-2y^{2}$
Let
    $[p,q,r,s]=[1,0,0,2],\quad [p^{\prime },q^{\prime },r^{\prime },s^{\prime }]=[0,2,5,3]$
We have
    $pq^{\prime }-qp^{\prime }=2,pr^{\prime }-rp^{\prime }=5,ps^{\prime }-sp^{\prime }=3,qr^{\prime }-rq^{\prime }=0,qs^{\prime }-sq^{\prime }=4,rs^{\prime }-sr^{\prime }=10$.
These six numbers have no common divisors other than ±1. Let
    $X=pxu+qxv+ryu+syv=xu+2yv$,
    $Y=p^{\prime }xu+q^{\prime }xv+r^{\prime }yu+s^{\prime }yv=2xv+5yu+3yv$.
Then it can be verified that
    $g(x,y)h(u,v)=F(X,Y)$.
Hence $F(x,y)$ is a composite of $g(x,y)$ and $h(x,y)$.

## An algorithm to find the composite of two IBQFs

The following algorithm can be used to compute the composite of two IBQFs.

### Algorithm

Given the following IBQFs having the same discriminant $\Delta$:
    $f_{1}(x,y)=a_{1}x^{2}+b_{1}xy+c_{1}y^{2}$
    $f_{2}(x,y)=a_{2}x^{2}+b_{2}xy+c_{2}y^{2}$
    $\Delta =b_{1}^{2}-4a_{1}c_{1}=b_{2}^{2}-4a_{2}c_{2}$
      * Compute $\beta ={\frac {b_{1}+b_{2}}{2}}$
      * Compute $n=\gcd(a_{1},a_{2},\beta )$
      * Compute $t,u,v$ such that $a_{1}t+a_{2}u+\beta v=n$
      * Compute $A={\frac {a_{1}a_{2}}{n^{2}}}$
      * Compute $B={\frac {a_{1}b_{2}t+a_{2}b_{1}u+v(b_{1}b_{2}+\Delta )/2}{n}}$
      * Compute $C={\frac {B^{2}-\Delta }{4A}}$
      * Compute $F(x,y)=Ax^{2}+Bxy+Cy^{2}$
      * Compute
             $X=nx_{1}x_{2}+{\frac {(b_{2}-B)n}{2a_{2}}}x_{1}y_{2}+{\frac {(b_{1}-B)n}{2a_{1}}}y_{1}x_{1}+{\frac {[b_{1}b_{2}+\Delta -B(b_{1}+b_{2})]n}{4a_{1}a_{2}}}y_{1}y_{2}$
             $Y={\frac {a_{1}}{n}}x_{1}y_{2}+{\frac {a_{2}}{n}}y_{1}x_{1}+{\frac {b_{1}+b_{2}}{2n}}y_{1}y_{2}$
Then $F(X,Y)=f_{1}(x_{1},y_{1})f_{2}(x_{2},y_{2})$ so that $F(x,y)$ is a composite of $f_{1}(x,y)$ and $f_{2}(x,y)$.

## Properties of the composition law
### Existence of the composite

The composite of two IBQFs exists if and only if they have the same discriminant.

### Equivalent forms and the composition law

Let $g(x,y),h(x,y),g^{\prime }(x,y),h^{\prime }(x,y)$ be IBQFs and let there be the following equivalences:
    $g(x,y)\sim g^{\prime }(x,y)$
    $h(x,y)\sim h^{\prime }(x,y)$
If $F(x,y)$ is a composite of $g(x,y)$ and $h(x,y)$, and $F^{\prime }(x,y)$ is a composite of $g^{\prime }(x,y)$ and $h^{\prime }(x,y)$, then
    $F(x,y)\sim F^{\prime }(x,y).$

### A binary operation

Let $D$ be a fixed integer and consider set $S_{D}$ of all possible primitive IBQFs of discriminant $D$. Let $G_{D}$ be the set of equivalence classes in this set under the equivalence relation "$\sim$". Let $[g(x,y)]$ and $[h(x,y)]$ be two elements of $G_{D}$. Let $F(x,y)$ be a composite of the IBQFs $g(x,y)$ and $h(x,y)$ in $S_{D}$. Then the following equation
    $[g(x,y)]\circ [h(x,y)]=[F(x,y)]$
defines a well-defined binary operation "$\circ$" in $G_{D}$.

### The group G$_D$

* The set $G_{D}$ is a finite abelian group under the binary operation $\circ$.
* The identity element in the group $G_{D}$ = ${\begin{cases}[x^{2}-(D/4)y^{2}]&{\text{ if }}D\equiv 0\,(\mathrm {mod} \,\,4)\\[1mm][x^{2}+xy+((1-D)/4)y^{2}]&{\text{ if }}D\equiv 1\,(\mathrm {mod} \,\,4)\end{cases}}$
* The inverse of $[ax^{2}+bxy+cy^{2}]$ in $G_{D}$ is $[ax^{2}-bxy+cy^{2}]$.

## Modern approach to the composition law

The following sketch of the modern approach to the composition law of IBQFs is based on a monograph by Duncan A. Buell. The book may be consulted for further details and for proofs of all the statements made hereunder.

### Quadratic algebraic numbers and integers

Let $\mathbb {Z}$ be the set of integers. Hereafter, in this section, elements of $\mathbb {Z}$ will be referred as rational integers to distinguish them from algebraic integers to be defined below.
A complex number $\alpha$ is called a quadratic algebraic number if it satisfies an equation of the form
    $ax^{2}+bx+c=0$ where $a,b,c\in \mathbb {Z}$.
$\alpha$ is called a quadratic algebraic integer if it satisfies an equation of the form
    $x^{2}+bx+c=0$ where $b,c\in \mathbb {Z}$
The quadratic algebraic numbers are numbers of the form
    $\alpha ={\frac {-b+e{\sqrt {d}}}{2a}}$ where $a,b,d,e\in \mathbb {Z}$ and $d$ has no square factors other than $1$.
The integer $d$ is called the radicand of the algebraic integer $\alpha$. The norm of the quadratic algebraic number $\alpha$ is defined as
    $N(\alpha )=(b^{2}+e^{2}d)/4a^{2}$.
Let $\mathbb {Q}$ be the field of rational numbers. The smallest field containing $\mathbb {Q}$ and a quadratic algebraic number $\alpha$ is the quadratic field containing $\alpha$ and is denoted by $\mathbb {Q} (\alpha )$. This field can be shown to be
    $\mathbb {Q} (\alpha )=\mathbb {Q} ({\sqrt {d}})=\{t+u{\sqrt {d}}\,|\,t,u\in \mathbb {Q} \}$
The discriminant $\Delta$ of the field $\mathbb {Q} ({\sqrt {d}})$ is defined by
    $\Delta ={\begin{cases}4d&{\text{ if }}d\equiv 2{\text{ or }}3\,\,(\mathrm {mod} \,\,4)\\[1mm]d&{\text{ if }}d\equiv 1\,\,(\mathrm {mod} \,\,4)\end{cases}}$
Let $d\neq 1$ be a rational integer without square factors (except 1). The set of quadratic algebraic integers of radicand $d$ is denoted by $O({\sqrt {d}})$. This set is given by
    $O({\sqrt {d}})={\begin{cases}\{a+b{\sqrt {d}}\,|\,a,b\in \mathbb {Z} \}&{\text{ if }}d\equiv 2{\text{ or }}3\,\,(\mathrm {mod} \,\,4)\\[1mm]\{(a+b{\sqrt {d}})/2\,|\,a,b\in \mathbb {Z} ,a\equiv b\,\,\mathrm {mod} \,\,2)\}&{\text{ if }}d\equiv 1\,\,(\mathrm {mod} \,\,4)\}\end{cases}$
$O({\sqrt {d}})$ is a ring under ordinary addition and multiplication. If we let
    $\delta ={\begin{cases}-{\sqrt {d}}&{\text{ if }}\delta {\text{ is even}}\\[1mm](1-{\sqrt {d}})/2&{\text{ if }}\delta {\text{ is odd}}\end{cases}}$
then
    $O({\sqrt {d}})=\{a+b\delta \,|\,a,b\in \mathbb {Z} \}$.

### Ideals in quadratic fields

Let $\mathbf {a}$ be an ideal in the ring of integers $O({\sqrt {d}})$; that is, let $\mathbf {a}$ be a nonempty subset of $O({\sqrt {d}})$ such that for any $\alpha ,\beta \in \mathbf {a}$ and any $\lambda ,\mu \in O({\sqrt {d}})$, $\lambda \alpha +\mu \beta \in \mathbf {a}$. (An ideal $\mathbf {a}$ as defined here is sometimes referred to as an integral ideal to distinguish from fractional ideal to be defined below.) If $\mathbf {a}$ is an ideal in $O({\sqrt {d}})$ then one can find $\alpha _{1},\alpha _{2}\in O({\sqrt {d}})$ such any element in $\mathbf {a}$ can be uniquely represented in the form $\alpha _{1}x+\alpha _{2}y$ with $x,y\in \mathbb {Z}$. Such a pair of elements in $O({\sqrt {d}})$ is called a basis of the ideal $\mathbf {a}$. This is indicated by writing $\mathbf {a} =\langle \alpha _{1},\alpha _{2}\rangle$. The norm of $\mathbf {a} =\langle \alpha _{1},\alpha _{2}\rangle$ is defined as
    $N(\mathbf {a} )=|\alpha _{1}{\overline {\alpha _{2}}}-{\overline {\alpha _{1}}}\alpha _{2}|/{\sqrt {\Delta }}$.
The norm is independent of the choice of the basis.

### Some special ideals

* The product of two ideals $\mathbf {a} =\langle \alpha _{1},\alpha _{2}\rangle$ and $\mathbf {b} =\langle \beta _{1},\beta _{2}\rangle$, denoted by $\mathbf {a} \mathbf {b}$, is the ideal generated by the $\mathbb {Z}$-linear combinations of $\alpha _{1}\beta _{1},\alpha _{1}\beta _{2},\alpha _{2}\beta _{1},\alpha _{2}\beta _{2}$.
* A fractional ideal is a subset $I$ of the quadratic field $\mathbb {Q} ({\sqrt {\Delta }})$ for which the following two properties hold:
   * For any $\alpha ,\beta \in I$ and for any $\lambda ,\mu \in O({\sqrt {d}})$, $\lambda \alpha +\mu \beta \in I$.
   * There exists a fixed algebraic integer $\nu$ such that for every $\alpha \in I$, $\nu \alpha \in O({\sqrt {d}})$.
* An ideal $\mathbf {a}$ is called a principal ideal if there exists an algebraic integer $\alpha$ such that $\mathbf {a} =\{\lambda \alpha \,|\,\lambda \in O({\sqrt {d}})\}$. This principal ideal is denoted by $(\alpha )$.
There is this important result: "Given any ideal (integral or fractional) $\mathbf {a}$, there exists an integral ideal $\mathbf {b}$ such that the product ideal $\mathbf {ab}$ is a principal ideal."

### An equivalence relation in the set of ideals

Two (integral or fractional) ideals $\mathbf {a}$ and $\mathbf {b}$ ares said to be equivalent, dented $\mathbf {a} \sim \mathbf {b}$, if there is a principal ideal $(\alpha )$ such that $\mathbf {a} =(\alpha )\mathbf {b}$. These ideals are narrowly equivalent if the norm of $\alpha$ is positive. The relation, in the set of ideals, of being equivalent or narrowly equivalent as defined here is indeed an equivalence relation.
The equivalence classes (respectively, narrow equivalence classes) of fractional ideals of a ring of quadratic algebraic integers $O({\sqrt {d}})$ form an abelian group under multiplication of ideals. The identity of the group is the class of all principal ideals (respectively, the class of all principal ideals $(\alpha )$ with $N(\alpha )>0$). The groups of classes of ideals and of narrow classes of ideals are called the class group and the narrow class group of the $\mathbb {Q} ({\sqrt {d}})$.

### Binary quadratic forms and classes of ideals

The main result that connects the IBQFs and classes of ideals can now be stated as follows:
    "The group of classes of binary quadratic forms of discriminant $\Delta$ is isomorphic to the narrow class group of the quadratic number field $\mathbb {Q} ({\sqrt {\Delta }})$."

## Bhargava's approach to the composition law

Manjul Bhargava, a Canadian-American Fields Medal winning mathematician introduced a configuration, called a Bhargava cube, of eight integers $a,b,c,d,e,f$ (see figure) to study the composition laws of binary quadratic forms and other such forms. Defining matrices associated with the opposite faces of this cube as given below
    $M_{1}={\begin{bmatrix}a&b\\c&d\end{bmatrix}},N_{1}={\begin{bmatrix}e&f\\g&h\end{bmatrix}},M_{2}={\begin{bmatrix}a&c\\e&g\end{bmatrix}},N_{2}={\begin{bmatrix}b&d\\f&h\end{bmatrix}},M_{3}={\begin{bmatrix}a&e\\b&f\end{bmatrix}},N_{3}={\begin{bmatrix}c&g\\d&h\end{bmatrix}}$,
Bhargava constructed three IBQFs as follows:
    $Q_{1}=-\det(M_{1}x+N_{1}y),\,\,Q_{2}=-\det(M_{2}x+N_{2}y)\,\,Q_{3}=-\det(M_{3}x+N_{3}y)$
Bhargava established the following result connecting a Bhargava cube with the Gauss composition law:
    "If a cube A gives rise to three primitive binary quadratic forms Q$_1$, Q$_2$, Q$_3$, then Q$_1$, Q$_2$, Q$_3$ have the same discriminant, and the product of these three forms is the identity in the group defined by Gauss composition. Conversely, if Q$_1$, Q$_2$, Q$_3$ are any three primitive binary quadratic forms of the same discriminant whose product is the identity under Gauss composition, then there exists a cube A yielding Q$_1$, Q$_2$, Q$_3$."