Reduction algorithm for a positive definite binary quadratic form (source code)

= Reduction algorithm for a positive definite binary quadratic form

For a positive definite integral form $[a,b,c]$, a unimodular shear can replace $b$ by its representative $b'$ with $|b'|\leq a$. If the resulting $c'=(b'^2-D)/(4a)$ is smaller than $a$, swapping the variables replaces the leading coefficient by the smaller positive integer $c'$. Repeating terminates and produces $|b|\leq a\leq c$; determinant-one sign changes enforce the boundary convention. Thus every positive definite integral binary quadratic form is properly equivalent to a reduced form.