Enumeration of reduced binary quadratic forms (source code)

= Enumeration of reduced binary quadratic forms

For a reduced form of negative discriminant $D$, the inequalities imply $3a^2\leq|D|$. One can therefore enumerate all classes by checking the finite set
$$
1\leq a\leq\sqrt{|D|/3},\qquad |b|\leq a,
$$
and retaining integral $c=(b^2-D)/(4a)$ with $a\leq c$ and the boundary sign convention.