Algorithm for finding all reduced ternary quadratic forms
of level N and discriminant d.

Larry Lehman
Mary Washington College

If f(x,y,z) = ax2 + by2 + cz2 + ryz + sxz + txy is a positive definite, primitive, ternary quadratic form, (a ternary form, for short) then its discriminant is given by d = 4abc + rst - ar2 - bs2 - ct2, and its level is N = 4d/m where m is the greatest common divisor of 4bc-r2, 4ac-s2, 4ab-t2, 2st-4ar, 2rt-4bs, and 2rs-4ct. (Since f is positive definite, each of a, b, c, 4bc-r2, 4ac-s2, 4ab-t2, and d is positive.)

Every ternary form is equivalent to exactly one reduced form, which, by definition, satisfies the following conditions:

It can be shown that if f is reduced, then abc is greater than or equal to d/4 and less than or equal to d/2. Furthermore, the following facts are easy to establish:

Using these facts, we have the following algorithm for finding all reduced ternary forms having discriminant d and level N.

Algorithm:

Given N and d, let m = 4d/N and mu = 4N/m. (If these are not integers, then there are no ternary forms of this level and discriminant.)
  1. Let a vary from 1 to the greatest integer less than or equal to the cube root of d/2, subject to the condition that if mu is odd, then a is congruent to 0 or -mu modulo 4. For each a, use the Euclidean Algorithm to find the greatest common divisor, g, of 4a and m, and integers u and v such that g = 4au + mv.
  2. Given a, let t vary from 0 to a, subject to the conditions that if m is even, then t is even, and that g divides t2.
  3. Given a and t, let b vary over all integers congruent to ut2/g modulo m/g, such that b is greater than or equal to the larger of a and m/4a, b is less than or equal to the square root of d/2a, and subject to the condition that if mu is odd, then b is congruent to 0 or -mu modulo 4. (Note: In this step and the previous one, we are using the fact that 4ab-t2 must be divisible by m. Thus b is a solution of the linear congruence 4ax = t2 (mod m). This congruence has a unique solution modulo m/g, namely ut2/g, if and only if g divides t2.)
  4. Given a, t, and b, let s vary from 0 to a, subject to the conditions that if m is even, then s is even, and that g divides 2st.
  5. Given a, t, b, and s, let r vary over all integers that are congruent to 2stu/g modulo m/g, that are less than or equal to b in absolute value, and such that if m is even, then r is even, and if st = 0, then r is less than or equal to 0. (In this step and the previous one, we use the fact that 2st-4ar is divisible by m.)
  6. Given a, t, b, s, and r, test whether c = (d - rst + ar2 + bs2)/(4ab - t2) is an integer. If so, test whether a, b, c, r, s, and t satisfy all the other properties of a reduced ternary form of level N and discriminant d. (If r is less than or equal to 0, replace s and t by their negatives. It is easy to see that any two of r, s, and t can be changed in sign without affecting the invariants N and d.)


Return to Research Information - Larry Lehman (List of Tables)